“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

相关推荐
澈207几秒前
C++面向对象:类与对象核心解析
c++·算法
小短腿的代码世界12 分钟前
Qt跨进程通信在交易系统中的应用:让策略引擎与风控模块在毫秒级握手
开发语言·qt
6Hzlia16 分钟前
【Hot 100 刷题计划】 LeetCode 141. 环形链表 | C++ 哈希表直觉解法
c++·leetcode·链表
zhangrelay24 分钟前
三分钟云课实践速通--大学物理--python 版
linux·开发语言·python·学习·ubuntu·lubuntu
MegaDataFlowers1 小时前
调用Service层操作数据
java·开发语言
asdzx671 小时前
使用 Python 读取 PDF: 提取文本和图片
开发语言·python·pdf
handler011 小时前
Linux 进程探索:从 PCB 管理到 fork() 的写时拷贝
linux·c语言·c++·笔记·学习
沐知全栈开发1 小时前
jQuery Mobile 表单选择
开发语言
MoonBit月兔1 小时前
MoonBit 大型软件合成挑战赛决赛暨 Meetup 0.9 版本专场回顾
大数据·开发语言·人工智能·moonbit
宣宣猪的小花园.1 小时前
C语言重难点全解析:指针到内存四区
c语言·开发语言