Possible Duplicate:
C++ delete – It deletes my objects but I can still access the data?
Why doesn't delete destroy anything?
I’ve Created dynamic array, and I added values to the values of the array like that.
int *pArr;
pArr = new int[10];
for(int i=0;i<10;i++){
pArr[i] = i+2;
}
delete[] pArr;
// After deletion I can find the value of the array items.
cout << pArr[5] << endl;
As you see in the code above and in the last line, I can output the fifth element in the array without any problem .
With that supposed to be the array has been removed.
To show that the memory can be used again, consider this expansion of your code:
That prints out
12for me. i.e. the value frompArr2[5]actually. Or at least I should say it does for my machine with my specific compiler & version, etc. As others have pointed out it is undefined behaviour. But hopefully my example shows you at least one kind of undefined behaviour.