标签:delete names main cout int amp ace namespace nbsp
直接上代码感受一下:
#include <iostream>
using namespace std;
int main()
{
int a=3;
int* p1=&a;
int* p2=new int(8);
cout<<a<<‘ ‘<<*p1<<‘ ‘<<p1<<‘ ‘<<*p2<<‘ ‘<<p2<<endl;
delete p1;
delete p2;
cout<<a<<‘ ‘<<*p1<<‘ ‘<<p1<<‘ ‘<<*p2<<‘ ‘<<p2<<endl;
return 0;
}
输出结果:
3 3 0x28fef4 8 0x731870
3 3 0x28fef4 22 0x731870
由此可见结论如题所示。
C++ delete掉的是new出的堆区内存,无法delete掉栈区的内存
标签:delete names main cout int amp ace namespace nbsp
原文地址:http://www.cnblogs.com/tan13hu/p/7088894.html