空悬指针和野指针的区别(the difference between dangling pointer and wild pointer)

看c++知识不短时间了,原来一直不知道空悬指针和野指针什么区别,一直以为它们是一个意思,而且不靠谱的度娘也没给我靠谱的解释。在yahoo answers看到了很不错的解释:
A dangling pointer is a pointer that used to point to a valid address but now no longer does. This is usually due to that memory location being freed up and no longer available. There is nothing wrong with having a dangling pointer unless you try to access the memory location pointed at by that pointer. It is always best practise not to have or leave dangling pointers. 
空悬指针是这样一种指针:它曾经指向一个有效地址,但是现在不再指向有效地址(个人添加,其实就是原来的那块地址不能通过这个指针区访问了)。这通常是因为指针所指的内存单位被释放了并且不再有效了。空悬指针存在并没有什么问题,除非你尝试通过这个指针访问指向的地址空间。不遗留任何悬空指针总是最好的实践方式。
A wild pointer is a pointer that has not been correctly initialised and therefore points to some random piece of memory. It is a serious error to have wild pointers. 
而野指针是这样一种指针:它没有被正确的初始化于是指向一个随机的内存地址。存在野指针是一个严重的错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值