“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

相关推荐
CodeCraft Studio3 小时前
Excel处理控件Aspose.Cells教程:使用 C# 从 Excel 进行邮件合并
开发语言·c#·excel
小超爱编程3 小时前
纯前端做图片压缩
开发语言·前端·javascript
曼巴UE55 小时前
UE5 音效系统
c++·游戏·ue5·虚幻·音效
KIDAKN6 小时前
java--怎么定义枚举类
java·开发语言
海天胜景6 小时前
C# 中常用的 字符串截取方法
开发语言·c#
无影无踪的青蛙6 小时前
[C++] list双向链表使用方法
c++·链表·list
tkevinjd7 小时前
C++中线程库的基本操作
开发语言·c++
CodeWithMe7 小时前
【C/C++】不同防止头文件重复包含的措施
c语言·开发语言·c++
Fre丸子_7 小时前
C++定长内存块的实现
c++
子豪-中国机器人7 小时前
C++ 信息学奥赛总复习题答案解析
开发语言·c++·算法