Chapter 4 Arrays and Pointers

4.3 -- C-Style Character Strings

When we allocate memory, we must eventually free it. Otherwise, memory is gradually used up and may be exhausted. When we no longer need the array, we mustexplicitly return its memory to the free store. We do so by applying thedelete [] expression to a pointer that addresses the array we want to release:

delete [] pia;

deallocates the array pointed to by pia, returning the associated memory to the free store. The empty bracket pair between thedelete keyword and the pointer is necessary:It indicates to the compiler that the pointer addresses an array of elements on the free store and not simply a single object.

Beware:

If the empty bracket pair is omitted, it is an error, but an error that the compiler is unlikely to catch; the program may fail at run time.


你可能感兴趣的:(Chapter 4 Arrays and Pointers)