“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

相关推荐
aramae1 分钟前
C++ IO流完全指南:从C标准库到C++流式编程
服务器·c语言·开发语言·c++·后端
ZHOU_WUYI4 分钟前
4. light wam 模型loss计算过程
开发语言·人工智能·python
_wyt00118 分钟前
c++里的族谱:树
c++·
长不胖的路人甲1 小时前
Serial 串行、Parallel 并行、CMS 并发收集器
java·开发语言·jvm
@三十一Y1 小时前
C++:AVL树实现
c++
ShineWinsu2 小时前
对于Linux:传输层协议UDP原理的解析
linux·c++·面试·udp·协议·传输层·计算机系统
LingzhiPi2 小时前
零知派ESP32--AS5600磁吸旋钮音量控制器
c++·单片机·嵌入式硬件
麻瓜老宋2 小时前
AI开发C语言应用按步走,表达式计算器calc的第二十四步,结束开发,生成calc 用法指南
c语言·开发语言·atomcode
小保CPP2 小时前
OpenCV C++车型识别1-图像预处理
c++·人工智能·opencv·计算机视觉
霸道流氓气质2 小时前
分布式系统中接口时序不确定性处理
java·开发语言·分布式