What happens under the hood when you call delete vs. delete[]? Why is it undefined behavior to mix them?

Last updated 21 June 2026

  • delete runs one destructor then frees. delete[] destroys every element, often using an element count (cookie) stored by new[] just before the pointer.

  • Mixing them is UB: skipped destructors, freeing from the wrong address, or reading a nonexistent count, which can corrupt the heap.

  • Always match the form of new, or avoid the choice with std::vector or std::unique_ptr<T[]>.

  • https://saco-evaluator.org.za/docs/cppreference/en/cpp/language/delete.html
All C++ interview questions