Deleting array of pointers

Krzysztof Stanisławek picture Krzysztof Stanisławek · Feb 12, 2014 · Viewed 17.6k times · Source

Does delete[] a, where a is dynamic-allocated array of pointers, execute delete for each pointer in array?

I suppose, it executes destructor for arrays with user-defined classes, but what's happening with pointers?

Answer

juanchopanza picture juanchopanza · Feb 12, 2014

No, delete [] is used to delete an array. If you need to delete array elements, you need to call delete on each one of them.