https://blog.csdn.net/qq_41620518/article/details/88363614
在调试代码时遇到如下问题
1、单步调试,在运行第6行delete之前的输出为:
int main()
{
int *a =new int (1000);
cout << a << endl;
cout << sizeof(a) << endl;
delete a;
cout << sizeof(a) << " " << a << endl;
a = NULL;
cout << sizeof(a) << " " << a << endl;
return 0;
}
1、查看a地址对应的内存为:(int占4位字节,即7c08-7c0B:00-00-03-e8)
(指针占4位字节,即fd-fd-fd-fd,指针为什么是fd-fd-fd-fd)
2、运行delete a后,内存查看如下:
(为啥好些内存都变为了dd-dd-dd……)
3、此后的输出为,也证明了delete a后指针并不会销毁,还需要将a赋值NULL,防止a变为野指针。
但为什么a指向的地址会变,不是应该不变的吗?