The error is clear, I think: just change
for (int i = 0; i < 10; ++i)
or change the size of array to 12.
1. The difference between delete and delete[]
From the standard (5.3.5/2) :
In the first alternative (delete object), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object (1.8) representing a base class of such an object (clause 10). If not, the behavior is undefined.
In the second alternative (delete array), the value of the operand of delete shall be the pointer value which resulted from a previous array new-expression. If not, the behavior is undefined.
2, 3. How does the compiler know the size of a array when using delete [] ?
How does the compiler know the tail of p and stop deleting?
It is unspecified how the size information is stored, so each compiler may implement it in a different way, but a common way to do it is to allocate an extra block before the array. That is, when you do this:
int* p = new int[10];
it actually allocates an array of 11 integers, and stores the array size in the first element