“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

相关推荐
charlie1145141916 分钟前
嵌入式现代C++教程实战篇第12篇:C宏时代的LED驱动 —— 能跑但不优雅
c语言·c++·stm32·单片机·嵌入式硬件·c
wunaiqiezixin13 分钟前
链表多项式大整数-BigInt
数据结构·c++·链表
亚空间仓鼠14 分钟前
Python学习日志(四):实例
开发语言·python·学习
Fanfanaas16 分钟前
Linux 系统编程 进程篇 (二)
linux·运维·服务器·c语言·开发语言·学习
kyle~19 分钟前
BFS(广度优先搜索)与 DFS (深度优先搜索)
c++·算法·深度优先·宽度优先
油丶酸萝卜别吃19 分钟前
高效处理数组差异:JS中新增、删除、交集的最优解(Set实现)
开发语言·前端·javascript
HoneyMoose21 分钟前
Npmp 安装时候提示警告: error (ERR_INVALID_THIS)
开发语言
汉克老师22 分钟前
GESP2024年3月认证C++三级( 第二部分判断题(1-10))
c++·位运算·string·gesp三级·gesp3级
gskyi22 分钟前
时间格式化神器:智能显示相对时间
开发语言·javascript·ecmascript
古城小栈27 分钟前
Rust在当下AI领域的用武之地:从底层加速到上层应用全解析
开发语言·人工智能·rust