I\'m new to C++, and I\'m confused about arrays and pointers. Could someone tell me how I can properly delete a pointer. Like for example,
int *foo;
foo = ne
It's:
delete[] foo;
Edit: Modern compilers really need you to use the correct delete
operator, or they may leak memory or fail to run the proper destructors.
(I earlier stated that it didn't make a difference in practice. About 10 years ago, I tried many different compilers and failed to find one that actually leaked memory if you mistakenly omitted the []
. However the howls of the mob - see below - have forced me to re-try my experimentation, and it seems that modern compilers/libc++s really do care.)