“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

相关推荐
honder试试27 分钟前
焊接自动化测试平台图像处理分析-模型训练推理
开发语言·python
^Rocky32 分钟前
JavaScript性能优化实战
开发语言·javascript·性能优化
田里的水稻40 分钟前
C++_队列编码实例,从末端添加对象,同时把头部的对象剔除掉,中的队列长度为设置长度NUM_OBJ
java·c++·算法
ponnylv1 小时前
深入剖析Spring Boot启动流程
java·开发语言·spring boot·spring
萧邀人1 小时前
第一课、Cocos Creator 3.8 安装与配置
开发语言
Jayden_Ruan2 小时前
C++逆向输出一个字符串(三)
开发语言·c++·算法
不吃鱼的羊2 小时前
启动文件Startup_vle.c
c语言·开发语言
liulun2 小时前
Skia如何渲染 Lottie 动画
c++·动画
VBA63372 小时前
VBA之Word应用第四章第二节:段落集合Paragraphs对象(二)
开发语言
点云SLAM3 小时前
C++ 常见面试题汇总
java·开发语言·c++·算法·面试·内存管理