Difference between pointer to a new element and new array?

When using new [] some c++ implementations will track the size of the allocation of the array in the address before the pointer returned. This is an implementation detail not defined by the standard.

The following answer describes this possible implementation in a little more detail: How could pairing new[] with delete possibly lead to memory leak only?

You must always match new with delete and new [] with delete []. It is Undefined Behavior to mix these.


The pointers themselves are completely indistinguishable. That's why you must remember to match new/delete and new[]/delete[].

Mismatching them triggers undefined behaviour.

Tags:

C++