“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

相关推荐
是翔仔呐1 分钟前
第13章 SPI通信协议全解:底层时序、4种工作模式与W25Qxx Flash芯片读写实战
c语言·开发语言·stm32·单片机·嵌入式硬件·学习·gitee
2401_878530218 分钟前
自定义内存布局控制
开发语言·c++·算法
wjs202413 分钟前
SQLite 子查询
开发语言
AndrewMe821118 分钟前
detailed-docx:一个能保住格式的 Word 文档操作库
开发语言·python·word
IT方大同22 分钟前
RT_thread(RTOS实时操作系统)线程的创建与切换
c语言·开发语言·嵌入式硬件
智算菩萨27 分钟前
【OpenGL】6 真实感光照渲染实战:Phong模型、材质系统与PBR基础
开发语言·python·游戏引擎·游戏程序·pygame·材质·opengl
jinanwuhuaguo27 分钟前
OpenClaw深度沟通渠道-全景深度解构
大数据·开发语言·人工智能·openclaw
是翔仔呐28 分钟前
第14章 CAN总线通信全解:底层原理、帧结构与双机CAN通信实战
c语言·开发语言·stm32·单片机·嵌入式硬件·学习·gitee
客卿12341 分钟前
用两个栈实现队列
android·java·开发语言
leaves falling41 分钟前
C++模板初阶:让代码“复制粘贴”自动化
开发语言·c++·自动化