“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

相关推荐
郝学胜-神的一滴12 小时前
Effective STL 条款15:注意字符串实现上的差异
java·开发语言·数据结构·c++·算法·visualstudio
sharemylove12 小时前
Java学习笔记 —— 面向对象专题
java·开发语言·笔记·学习·课程设计
代码民工正电荷13 小时前
JAVA学习基础(一)
java·开发语言·学习
星恒随风17 小时前
C++11 加餐(2)并发支持库——mutex、lock_guard、unique_lock 与死锁问题
开发语言·c++
AvocadoZeroOneOI17 小时前
Kadane 算法(最大子段和)
c++·学习·算法·动态规划
山楂树の19 小时前
Python Pandas 数据处理:数据读取、筛选、清洗、排序与分组
开发语言·python·pandas
汉克老师20 小时前
GESP六级第二课:森林里的分叉城堡——二叉树的构造与存储
c++·二叉树·树·gesp·小学生·小学生学编程
xurileidian20 小时前
第 22 篇 · 边玩边学Python · 双等号与 is 不是一回事
开发语言·python·spring
FRing0321 小时前
for循环、while循环、Java高级语法、数组
java·开发语言·后端·算法
syf06111321 小时前
Java Math 类详解:常用数学运算方法全解析
java·开发语言