I have the following case.
int *arrayP=new int[4];
arrayP[0]=0;arrayP[1]=1;arrayP[2]=2;arrayP[3]=3;
int *temp;
cout<<arrayP[0]<<endl;
temp=arrayP;
++arrayP;
cout<<arrayP[0];
cout<<arrayP[1];
delete temp;
cout<<arrayP[0];
Output
0
1
2
-1212222
Why is it so? arrayP points to the first element on the array of size 4. Thus temp also points to the first element Now why deleting the temp i.e first element also deletes the entire integer array.arrayP does store the address of the next element of the array and hence the array is not orphan.(I assume it has deleted the integer array as arrayP[0] is showing garbage value.)
If such is the case(i.e deleting temp will delete the entire integer array) whats the difference between delete[] and delete.