“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

相关推荐
王维同学10 分钟前
IFEO Debugger、VerifierDlls 与 SilentProcessExit 配置
c++·windows·安全·注册表
geovindu24 分钟前
CSharp: Iterative Algorithms
开发语言·后端·算法·c#·.net·迭代算法
小保CPP26 分钟前
OpenCV C++计算多边形的最大内切圆
c++·人工智能·opencv·计算机视觉
一只月月鸟呀39 分钟前
移动端tap与click的区别 && 点透事件
开发语言·前端·javascript
雨落在了我的手上40 分钟前
Java数据结构(六):链表的介绍
java·开发语言·数据结构
影寂ldy42 分钟前
C# HttpClient 分片下载、断点续传、暂停取消(完整项目知识点)
开发语言·c#
独隅1 小时前
DevEco Code Plan+Build 双 Agent 协同开发效率实测
java·开发语言
lueluelue472 小时前
八股临时总结
c++
KaMeidebaby2 小时前
卡梅德生物技术快报|抗体筛选:抗体筛选中的噬菌体展示四参数调优——从流程设计到数据验证
开发语言·前端·javascript
大黄说说2 小时前
接口频繁超时、报错?后端常见排查思路总结
开发语言·php