“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

相关推荐
琳少_6 小时前
java程序开发笔记
java·开发语言·数据库·笔记
七夜zippoe6 小时前
Agent 告警设计:分级告警、智能降噪与值班排班
开发语言·ai·agent·告警·智能降噪·值班排班
无忧.芙桃6 小时前
C++语言原理与实践(二十三):哈希表的实现
c++·链表·哈希算法·散列表·哈希表
严肃小白兔8 小时前
PHP 8.6 正式发布:部分函数应用、原生 I/O 轮询与新特性实战解析
开发语言·php
郝学胜-神的一滴8 小时前
Effective Python 条款36:优雅拼装迭代器与生成器
开发语言·数据结构·人工智能·python·numpy·scikit-learn
AvocadoZeroOneOI9 小时前
B4500 [GESP202603 三级] 凯撒密码 详细解题报告
c++·算法
wuyk5559 小时前
Python办公自动化-第04讲-批量新建Excel
开发语言·python·excel
code2cat10 小时前
【随笔】Java客户端选了HTTP/3,怎样知道请求实际走了哪个版本
java·开发语言·http
whitelbwwww11 小时前
cuBLAS--CUDA高性能线性代数计算库--第一部分
c++·线性代数·gpu算力·cuda c++
honker_X13 小时前
Python字符串全攻略:从入门到精通
开发语言·python