“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

相关推荐
_wyt0018 小时前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
LDR00610 小时前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术10 小时前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园10 小时前
C++20 Modules 模块详解
java·开发语言·spring
swordbob11 小时前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享11 小时前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.11 小时前
C语言--day30
c语言·开发语言
玖玥拾11 小时前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
何以解忧,唯有..12 小时前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽12 小时前
C语言不是语法,是通往机器的地图。
c语言·开发语言