Figure 17-6
Allocating Dynamic Data on the Free Store
Using the previous example, we can deallocate the dynamic data pointed to by intPtr and nameStr with the following statements.
delete intPtr;
Retruns the variable pointed to by intPtr to the free store to be used again. The value of intPtr is then undefined.
delete [] nameStr;
Returns the array pointed to by nameStr to the free store to be used again. The value of nameStr is then undefined.*
After execution of these statements, the values of intPtr and nameStr are undefined; they may or may not still point to the deallocated data. Before using these pointers again, you must assign new values to them (that is, store new memory addresses into them).
*The syntax for deallocating an array, delete [ ] nameStr, may not be accepted by some compilers. Early versions of the C++ language required the array size to be included within the brackets: delete [6] nameStr. If your compiler complains about the empty brackets, include the array size.