“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

相关推荐
luj_17685 分钟前
马克思的跨学科学术体系
c语言·开发语言·c++·经验分享·算法
阿文的代码库11 分钟前
干货分享|C++运算符重载知识点
java·c++·算法
码不停蹄的玄黓11 分钟前
Java 实现阻塞队列
java·开发语言
SunnyDays101111 分钟前
Java 实现 PDF 转 PDF/A 和 PDF/A 转 PDF(超详细教程)
java·开发语言·pdf
meilindehuzi_a13 分钟前
打破0基础:通过 5 个核心案例深度拆解 JavaScript 正则表达式与运行时类型系统
开发语言·javascript·正则表达式
Deep-w15 分钟前
【MATLAB】基于 MATLAB 的直流电动机双闭环调速系统建模与仿真
开发语言·算法·matlab
未若君雅裁21 分钟前
线程池核心参数与执行流程
java·开发语言
lbb 小魔仙22 分钟前
稳定比技巧更重要:海外多地区数据采集的经验教训
开发语言·javascript·ecmascript
pursue.dreams24 分钟前
Windows系统Golang超详细安装配置教程(2026最新、零基础)
开发语言·windows·golang
小小龙学IT29 分钟前
Go 后端并发实战:从 goroutine 到流水线架构
开发语言·架构·golang