I have this small piece of code in the middle of a larger code:
int *p = new int[100];
p += 50;
delete []p;
Will the compiler delete only the memory from the 51st location? I think it does. However, in the case of array pointers, the compiler holds an additional item which tells the number of objects allocated. So, in that case, shouldn't it go ahead and delete memory beyond the allocated size? Or does it delete the 51st–100th elements and keep the 1st–50th in the memory, in which case a memory leak can happen.