【发布时间】:2018-12-06 02:08:25
【问题描述】:
释放内存后,我希望指针指向被释放的内存。但它指向一些不同的地址。为什么会这样?
#include <iostream>
#include <string>
using namespace std;
int main() {
int* p = new int(4);
cout << p << endl; //address here is xxx
delete p;
cout << p << endl; //I expect it to be same xxx, but it is yyy
p = nullptr;
cout << p << endl; //no question here
system("pause");
return 0;
}
那么,yyy 内存位置到底是什么意思,为什么不是xxx?
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: c++