“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

相关推荐
tntxia4 分钟前
C++ 基础教程:从入门到精通
c++
Drone_xjw8 分钟前
从 GDB 到 CDB:C/C++ 程序调试的两把“手术刀”
c语言·开发语言·c++
SL-staff40 分钟前
智慧园区2000+设备统一管理:JVS-IoT如何降低运维成本40%
java·开发语言·物联网·智慧园区·设备管理·运维优化·jvs-iot
2zcode2 小时前
基于MATLAB图像处理的饮料瓶灌装液位检测系统设计与实现
开发语言·图像处理·matlab
必须得开心呀3 小时前
QT解决中文乱码问题
开发语言·qt
熊猫_豆豆3 小时前
QT6 Android C++ 自制美观闹钟
android·c++·qt·闹钟
随意起个昵称4 小时前
状压dp-基础题目2([USACO12MAR] Cows in a Skyscraper G)
c++·算法·动态规划
这不小天嘛4 小时前
JAVA八股——redis篇
java·开发语言·redis
无限的鲜花5 小时前
协程本质是函数加状态机——零基础深入浅出 C++20 协程
c++·算法·c++20
逝水无殇5 小时前
C# 字符串(String)详解
开发语言·后端·c#