提问人:YQ_AX 提问时间:10/8/2023 最后编辑:Jan SchultkeYQ_AX 更新时间:10/8/2023 访问量:64
复制从 new 获取的指针,然后删除时会发生什么情况?[复制]
What happens when you copy a pointer obtained from new, and then delete? [duplicate]
问:
这是一个基于 C++11 的问题。
当我通过另一个指针删除动态数组时会发生什么情况?这个动态数组真的被删除了吗?
int* a = new int[NUM01];
int* a1 = a;
for (int i = 0; i < NUM01; i++) {
a1[i] = 0;
}
delete[] a1; //What's happened?
我试着观察.a[0]
cout << a[0] << endl;
delete[] a1;
cout << a[0] << endl;
结果是: 0 -572662307
什么是真实的?
答: 暂无答案
评论
delete[] a
a
a1
std::vector<int>