“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

相关推荐
D e re k ZH几秒前
C++ 模板与泛型编程进阶(No 2)
开发语言·c++
一级新生4 分钟前
LLM _ Agent _ Skill _ 专家 的关系与选型笔记
java·开发语言·人工智能·笔记·大模型·智能体·skill
starzy19905 分钟前
Scala String操作:从插值器到正则的完整指南
开发语言·后端·scala
普通人67 分钟前
CSS-box-sizing-使用指南
开发语言·前端·css·1024程序员节
她说彩礼65万9 分钟前
C# TaskCompletionSource
java·开发语言·c#
青少儿编程课堂12 分钟前
蓝桥杯青少组图形化+信息素养+电子学会Scratch考级:校园口算闯关解析
c++·python·算法·bfs·信息学竞赛
eggwyw14 分钟前
C++深入浅出探索数据结构的原理
开发语言·c++
eggwyw16 分钟前
C++深入浅出讲解希尔排序算法的实现
开发语言·c++
starzy199019 分钟前
Scala Array操作:从定长数组到ArrayBuffer的完整指南
开发语言·后端·scala
读书札记202232 分钟前
Qt UTF-8和UTF-8(BOM)
开发语言·qt