Can I delete[] a pointer that points into an allocated array, but not to the start of it?

Viewed 2222

I'm wondering specifically about the following situation (which I discovered in some code I have to work with):

SomeClass *ar = new SomeClass[2];
ar++;
delete[] ar;

This code seems to be working fine - i.e. not crashing (win32, built with VS2005).

Is this "legal"? It certainly doesn't feel right.

7 Answers

enter image description here

If you don't pass the start of it, the delete won't get the extra info.

Related