Releasing Dynamically Allocated Built-In Arrays with delete []

To deallocate the memory to which gradesArray points, use the statement

delete [] gradesArray;

If the pointer points to a built-in array of objects, the statement first calls the destructor for every object in the array, then deallocates the memory. If the preceding statement did not include the square brackets ([]) and gradesArray pointed to a built-in array of objects, the result is undefinedsome compilers call the destructor only for the first object in the array. Using delete or delete [] on a nullptr has no effect.

Image Common Programming Error 10.3

Using delete instead of delete ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.