删除的指针指向什么? [英] What does a deleted pointer point to?

查看:38
本文介绍了删除的指针指向什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int*a=nullptr; //NULL before C++11
a=new int(1);
delete a;

a 现在指向什么?它指向 nullptr 还是指向它被删除之前指向的地址?

What does a point to now? Does it point to nullptr or does it point to the address it was pointing to before it was deleted?

推荐答案

其他一些答案错误地指出值不变".但是它确实是这样的:在删除之前它是有效的,而在删除之后它是无效的;这是一个变化.

A few other answers incorrectly say "the value doesn't change". However it does: before the deletion it was valid, and after the deletion it is invalid; this is a change.

此外,值的表示形式可能也会更改.例如,该实现可以将 a 设置为null,或者将调试器将识别出的某种模式,以帮助检测变量的无效使用.

Further, the representation of the value may change too. For example the implementation could set a to be null, or some pattern that the debugger will recognize to help with detecting invalid uses of variables.

这篇关于删除的指针指向什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆