delete vs delete[] operators in C++

shreyasva picture shreyasva · Mar 11, 2010 · Viewed 97.1k times · Source

What is the difference between delete and delete[] operators in C++?

Answer

Nick Meyer picture Nick Meyer · Mar 11, 2010

The delete operator deallocates memory and calls the destructor for a single object created with new.

The delete [] operator deallocates memory and calls destructors for an array of objects created with new [].

Using delete on a pointer returned by new [] or delete [] on a pointer returned by new results in undefined behavior.