Hi friends,
Can anyone tell me how to delete a double pointer ,means a pointer which contains the address of another pointer?
Thanks in Advance!!!!
This is a discussion on ***How to delete a pointer*** within the C++ Programming forums, part of the General Programming Boards category; Hi friends, Can anyone tell me how to delete a double pointer ,means a pointer which contains the address of ...
Hi friends,
Can anyone tell me how to delete a double pointer ,means a pointer which contains the address of another pointer?
Thanks in Advance!!!!
That depends on where the pointer points to and what happened previously. Anything that came from new should be delete'd -- that means that if you created (say) a faux two-dimensional array with new in a loop, you'll have to delete in a loop.
Dereference it to delete whatever is pointed at.
For example;
As always, nothing should be delete'd unless created using the corresponding operator new.Code:int main() { int **x = new (int *); *x = new int [5]; // now delete things in reverse order delete [] (*x); // brackets () for clarity delete x; }
Right 98% of the time, and don't care about the other 3%.
In two 2D array first delete the members and then the main pointer which is pointing towards the pointer to an array