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!!!!
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; }
In two 2D array first delete the members and then the main pointer which is pointing towards the pointer to an array