删除NULL但没有编译错误 [英] Delete NULL but no compile error

查看:43
本文介绍了删除NULL但没有编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑为什么下面的 C++ 代码可以编译.为什么调用delete 0的方法不报错?!

I'm confused why the following C++ code can compile. Why does a call to delete the method of 0 not produce any error?!

int *arr = NULL;     // or if I use 0, it's the same thing      
delete arr;

我确实尝试运行它,它根本没有给我任何错误...

I did try to run it, and it did not give me any error at all...

推荐答案

C++ 语言保证如果 p 等于空.

The C++ language guarantees that delete p will do nothing if p is equal to NULL.

有关更多信息,请查看第 16.8,9 节 此处:

For more info, check out Section 16.8,9 here:

这篇关于删除NULL但没有编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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