可能重复:
Can a local variable's memory be accessed outside its scope?内存管理问题
我有以下从那里我读这篇文章涉及到内存管理,源问题说, 当一个变量超出超出范围,该内存不再保证存储 变量的值 示例代码给出
int main() {
int *p;
if (true) {
int x = 5;
p = &x;
}
cout << *p << endl; // ???
}
它说也是 这里,对已经成为悬摆指针(指向的内存,其内容是不确定的) 但是这个代码显示了我结果5.so是错写这样的代码吗?请解释我
看看这个** [基本上相同的问题] **(http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope)**为了好的阅读。 – Anson
检出[this](http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope/“here”)post。 – Michael