May 2002
Beginner
320 pages
6h 18m
English
Deleting a heap-allocated pointer releases the storage it points to. delete comes in two forms: with [] (to delete an array), and without (to delete a regular variable).
Deleting is dangerous. Imagine what happens when you run this:
char *SomePointer = NULL; delete SomePointer;
or this:
char *SomePointer; delete SomePointer;
or:
char *SomePointer = new char; delete SomePointer; delete SomePointer;
or:
char *SomePointer = new char; delete SomePointer; char Stuff = *SomePointer;
As with using an invalid pointer or accessing beyond the end of an array, the consequences are unpredictable.
Read now
Unlock full access