“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

相关推荐
kyriewen1116 分钟前
给浏览器画个圈:CSS contain 如何让页面从“卡成PPT”变“丝滑如德芙”
开发语言·前端·javascript·css·chrome·typescript·ecmascript
娇娇yyyyyy1 小时前
QT编程(18): Qt QItemSelectionModel介绍
开发语言·qt
豆豆的java之旅1 小时前
软考中级软件设计师 数据结构详细知识点(含真题+练习题,可直接复习)
java·开发语言·数据结构
sthnyph1 小时前
QT开发:事件循环与处理机制的概念和流程概括性总结
开发语言·qt
大尚来也2 小时前
Java 反射:从“动态魔法”到生产实战的避坑指南
开发语言
无心水2 小时前
Java时间处理封神篇:java.time全解析
java·开发语言·python·架构·localdate·java.time·java时间处理
yangtuoni2 小时前
vscode调试C++程序
c++·ide·vscode
m0_587958952 小时前
C++中的命令模式变体
开发语言·c++·算法
~无忧花开~2 小时前
React生命周期全解析
开发语言·前端·javascript·react.js·前端框架·react
剑心诀2 小时前
02 数据结构(C) | 线性表——顺序表的基本操作
c语言·开发语言·数据结构