“nullptr“ should be used to denote the null pointer

Before C++11, the only way to refer to a null pointer was by using the integer literal 0, which created ambiguity with regard to whether a pointer or an integer was intended. Even with the NULL macro, the underlying value is still 0.

C++11 introduced the keyword nullptr, which is unambiguous and should be used systematically.

Noncompliant Code Example

cpp 复制代码
void f(char *c);
void g(int i);
void h()
{
    f(0); // Noncompliant
    f(NULL); // Noncompliant
    g(0); // Compliant, a real integer
    g(NULL); // Noncompliant, NULL should not be used for a real integer
}
复制代码
 

Compliant Solution

cpp 复制代码
void f(char *c);
void g(int i);
void h()
{
    f(nullptr); // Compliant
    g(0);  // Compliant, a real integer
}

See

For example

相关推荐
努力实干10 分钟前
面向对象设计原则——C++
开发语言·c++·数码相机
NetX行者2 小时前
四语言 Hello World 背后:编译模型与运行时对比
开发语言
Pin_Qing3 小时前
账单没超,请求先被拒了
大数据·开发语言·人工智能
2601_962885723 小时前
如何用 Python 计算 VaR 和 CVaR(在险价值)?
开发语言·python
郝亚军3 小时前
manifest 中 `sha256` 与 `signValue` 的作用
java·开发语言·数据结构
syagain_zsx3 小时前
jsoncpp 使用指南:编译链接、Json::Value 取值与高频坑
c++·json·库·http格式
譕痕3 小时前
stripe 实例
java·开发语言·stripe·checksession
墨子夕3 小时前
设计模式——Java × Python 双语言精讲 · 23 个经典模式 + 现代演进(前言篇)
java·开发语言·设计模式
_菜鸟果果3 小时前
高德地图 JS API 2.0 在国产 Linux/ARM 电脑上渲染失败 的排查与解决
linux·开发语言·javascript
布莱克6054 小时前
理解 = delete 与 = default:两种赋值语义的差异
c++