“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

相关推荐
通信瓦工2 分钟前
OCP 冷却环境与冷却剂分配单元(CDU)子项目
java·开发语言
91刘仁德10 分钟前
传输层协议深度拆解:端口寻址、UDP 报文与 TCP 可靠性机制全解析
linux·网络·c++·网络协议·tcp/ip·udp·c
Liuchang091115 分钟前
洛谷 P2670 [NOIP 2015 普及组] 扫雷游戏
c++·算法·游戏
坤坤子吖22 分钟前
Python基础语法学习:函数
开发语言·笔记·python·学习
言乐627 分钟前
Python体现逻辑回归和决策树的区别
开发语言·python·算法·决策树·逻辑回归
LOVE️YOU32 分钟前
Python 类与对象的核心逻辑:从 self、cls 到点号、括号与链式调用
开发语言·python
顶点多余38 分钟前
C/C++常见面试题
开发语言·c++
HugoStudio_SWAN40 分钟前
洛谷 B4575 [GESP202609 二级] 直角三角形——临场定义理解与边界质疑
c++·学习·程序人生·算法
(Charon)41 分钟前
【C++面试】右值引用与移动语义:std::move到底做了什么
开发语言·c++
TheITSea42 分钟前
JavaScript Web APIs
开发语言·前端·javascript