“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

相关推荐
by209997 小时前
从结构体到对象:正式学习C++类的骨架、封装与this指针
c++·经验分享·学习
乌暮7 小时前
深入理解 Java 泛型:把「万能盒子」用对、用稳
java·开发语言·后端·学习
2601_962218618 小时前
C语言中三种库的编译和使用方法
开发语言·c++
传奇开心果编程8 小时前
中庸、有容、破执:仓颉编程语言的中华智慧结晶——三重哲学境界思辨
开发语言·华为·开源·软件工程
jimy18 小时前
派生类重写基类虚函数(二):override的作用
开发语言·c++
_upupup8 小时前
异常(C++)
java·开发语言·jvm
ebiobiz8 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
hetao17338378 小时前
2026-09-29 hetao1733837 的刷题记录
c++·算法
:mnong8 小时前
几何内核“四大金刚“:ACIS、Parasolid、CGM、Open CASCADE 核心特征深度解析
c++·cad·cax
霸道流氓气质8 小时前
ComfyUI 图像生成工作流完全指南:从节点编排到Java生产级图像生产实战
java·开发语言·人工智能