“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 分钟前
StringBuffer 和 StringBuilder 高频面试题全解析
java·开发语言·面试
Pin_Qing11 分钟前
优惠期结束与计费周期更迭:Gemini 4 Carbon/Argon 价格调整后的架构应对
大数据·开发语言·人工智能·程序人生·架构
沫璃染墨15 分钟前
《Qt从零入门系列(十七):网络编程基础详解——从Socket原理到TCP/UDP通信API》
开发语言·网络·c++·qt·http·qt5·qt6.3
金榜题名萱16 分钟前
蓝桥杯|石子合并(区间动态规划)
c语言·数据结构·c++·算法·蓝桥杯·动态规划
SummerJokes18 分钟前
Java 异常处理完整详解|try‑catch‑finally、throws、throw、自定义异常实战
java·开发语言·python
ShineWinsu23 分钟前
对于Qt:绘图的解析
开发语言·数据库·c++·qt·面试·客户端·绘图
骑着蜗牛撵大象32727 分钟前
红外太阳能板缺陷检测:三端推理与数据集自动标注落地
开发语言·python·小程序·pyqt·yolov8·自动标注·红外缺陷检测
纪念 22931 分钟前
C++ 算法模板与错题 (前缀和)
开发语言·c++·算法
sharemylove1 小时前
Java 面向对象(OOP)笔记
java·开发语言·笔记·学习·课程设计
一个天蝎座 白勺 程序猿1 小时前
AI 学习者的编程技能:Python 高级特性详解(装饰器、生成器、魔法方法实战)
开发语言·人工智能·python·ai编程