之前学linux c++时候觉得new和delete能很简单形象的完成动态记忆体的配置,就没经过任何验证;可是今天闲着无聊,想看下其过程,
就先弄个简单的小程序
int main()
{
int *a=new int(9999);
cout<<a<<"\n";
cout<<*a<<"\n";
cout<<&a<<"\n";
delete a;
returen 0;
}
显示
0x80499c0
9999
0xbffffac4
没有问题;然后我看delete后的指针
int main()
{
int *a=new int(9999);
cout<<a<<"\n";
cout<<*a<<"\n";
cout<<&a<<"\n";
delete a;
cout<<a<<"\n";
cout<<*a<<"\n";
cout<<&a<<"\n";
returen 0;
}
显示
0x8049a98
9999
0xbffffac4
0x8049a98
9999
0xbffffac4
难道是delele一点作用都没有?
还是说虚拟机虚拟出来的记忆体自身有bug?请帮忙解除我疑惑;谢谢!