“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

相关推荐
_wyt00112 分钟前
拓扑排序:有向无环图的排队艺术
c++·拓扑排序·队列
皓月斯语13 分钟前
B2118 验证子串
c++·题解
乐观勇敢坚强的老彭31 分钟前
C++信奥:开关门、开关灯问题
开发语言·c++·算法
冻柠檬飞冰走茶32 分钟前
PTA基础编程题目集 7-31 字符串循环左移(C语言实现)
c语言·开发语言·数据结构·算法
a1117761 小时前
中文优先的企业 RAG 知识库 开源项目
开发语言·开源·kotlin
2301_777998341 小时前
C/C++:预处理详解
c语言·c++
破z晓1 小时前
javascript 导出excel表
开发语言·javascript·excel
t-think2 小时前
C++类和对象详解(一)
开发语言·c++
西门啐血2 小时前
上位机开发之假装有设备,使用 C# 模拟串口设备
开发语言·mongodb·c#
ask_baidu2 小时前
python实现Doris的streamLoad
开发语言·python