可能重复:
C++ delete - It deletes my objects but I can still access the data?
Why doesn't delete destroy anything?如何删除动态数组指针正确
我创建动态数组,和我的附加价值值像这样的数组。
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;
正如你在上面的代码和最后一行中看到的,我可以输出数组中的第五个元素而没有任何问题。 与那应该是数组已被删除。
你误解了'delete'的含义。内存不是GONE,你刚刚告诉C++你不会再使用它了。然后你破坏了你的诺言。 – 2012-01-11 16:27:33
给予+1的理由为什么c和C++不适合孩子。 – 2012-01-11 16:29:27
[你的圣经没有被触及。](http://stackoverflow.com/a/6445794/596781) – 2012-01-11 16:33:14