“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

相关推荐
不懒不懒几秒前
【卷积神经网络作业实现人脸的关键点定位功能】
开发语言·python
321.。1 分钟前
Linux 进程控制深度解析:从创建到替换的完整指南
linux·开发语言·c++·学习
酉鬼女又兒4 分钟前
零基础快速入门前端Web存储(sessionStorage & localStorage)知识点详解与蓝桥杯考点应用(可用于备赛蓝桥杯Web应用开发)
开发语言·前端·javascript·职场和发展·蓝桥杯·html
Bert.Cai6 分钟前
Python集合简介
开发语言·python
tryCbest10 分钟前
Java和Python开发项目部署简介
java·开发语言·python
ZTLJQ10 分钟前
任务调度的艺术:Python分布式任务系统完全解析
开发语言·分布式·python
小Tomkk11 分钟前
怎么配置 Visual Studio Code 配置 C/C++
c语言·c++·vscode
阿里嘎多学长12 分钟前
2026-03-31 GitHub 热点项目精选
开发语言·程序员·github·代码托管
CheerWWW14 分钟前
C++学习笔记——枚举、继承、虚函数、可见性
c++·笔记·学习
小只笨笨狗~20 分钟前
解决objectSpanMethod与expand共存时展开后表格错位问题
开发语言·javascript·ecmascript