“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

相关推荐
wjs202422 分钟前
JavaScript 条件语句
开发语言
阿里加多42 分钟前
第 1 章:Go 并发编程概述
java·开发语言·数据库·spring·golang
2301_792674861 小时前
java学习day29(juc)
java·开发语言·学习
周末也要写八哥1 小时前
MATLAB R2025a超详细下载与安装教程(附安装包)
开发语言·matlab
blog_wanghao2 小时前
基于Qt的串口调试助手
开发语言·qt
tankeven3 小时前
HJ176 【模板】滑动窗口
c++·算法
果汁华3 小时前
Typer:基于类型提示的现代Python CLI框架
开发语言·网络·python
赵药师3 小时前
多进程-生产者消费者C++实现
java·开发语言·jvm
OxyTheCrack3 小时前
【C++】一文详解C++智能指针自定义删除器(以Redis连接池为例)
c++·redis
雾岛听蓝3 小时前
Linux线程基础
linux·开发语言·经验分享