How do you delete a pointer to an array?
--C++angel
This is a discussion on Quick Question within the C++ Programming forums, part of the General Programming Boards category; How do you delete a pointer to an array? --C++angel...
How do you delete a pointer to an array?
--C++angel
delete[]
EDIT: Sorry if I was vague
anything you new with [] you have to delete with []..
I'm pretty sure that is the general rule of thumb
So if you have a pointer to an array..
and with that pointer you could do this pptr[]
you need to delete it like this
delete[] pptr[];
My syntax might be off, but the idea is there![]()
Last edited by Shamino; 03-09-2006 at 09:52 PM.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
just: delete [] pptr;
also, there are two reasons why it is extremely important to that syntax with arrays and *not* to use them on a single object:
1) most implementations hide a count of the array elements either in front of or at the end of the data bytes. using the above syntax on a single object could cause a runtime error since the library would be trying to access the count which would probably not be appended to a single object.
2) using the above syntax instructs the library to invoke the destructor on each element in the array.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}