“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

相关推荐
其实防守也摸鱼7 分钟前
Codex破局:前端组件秒级生成的技术文章大纲
开发语言·前端·人工智能·学习·安全·web安全
_Narcissus_18 分钟前
枚举和模拟算法笔记
c语言·数据结构·c++·笔记·算法·模拟·枚举
Logintern0918 分钟前
装饰器和洋葱模式的区分
开发语言·python·架构
冻柠檬飞冰走茶33 分钟前
《数据结构实验指导-C++语言版》 在顺序表 list 中查找元素 x
开发语言·数据结构·c++·算法·list
Brilliantwxx34 分钟前
【C++】 高阶数据结构图(1)并查集
开发语言·数据结构·c++
lancyu34 分钟前
# Agent Loop:AI Agent 的唯一直心骨
开发语言·javascript·人工智能
小鱼仙官1 小时前
Ubuntu C++ NTP校时程序
linux·c++·ubuntu
frjc1 小时前
阿里云 ACK 环境 Arthas 在线调试指南
开发语言·python
老当益壮梁奶奶2 小时前
Linux软件编程学习笔记(二)Linux文件IO编程入门:从fopen到fgetc
linux·c语言·c++·笔记·学习
雪的季节2 小时前
C++ 高级(泛型编程与模板)(有空再研究吧)
c++