“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

相关推荐
DLite14 分钟前
NLang 0.9.0发布:成为可嵌入语言
开发语言·编程语言·编译技术·nlang
有同事要进步18 分钟前
LeetCode 14. 最长公共前缀:纵向扫描一次讲透
开发语言·python
修船大队长23 分钟前
CanNm 从休眠唤醒后重复消息报文的周期与数量分析
开发语言·php
事圆则缓23 分钟前
Kotlin 变量与函数:把页面状态和行为写成清楚的契约
android·开发语言·kotlin
silvamux_35 分钟前
豆包 API 调用教程:Python 接入可跑通示例
开发语言·python
wdfk_prog1 小时前
LWIP教程 15:IPv4 与 IPv6——从网络层工作原理到嵌入式工程取舍
运维·开发语言·网络·笔记·学习·智能路由器·ip
棉猴1 小时前
玩游戏学Python10-算术运算符应用2
开发语言·python·玩游戏·游戏编程
tachibana21 小时前
Go 语言的 Map 是否是并发安全的?
开发语言·数据结构·后端·golang·go·语言
后除1 小时前
Go 实战: 使用 Wails v2.15 构建轻量级的桌面应用 - 仿微信登录界面
开发语言·微信·golang
坤坤子吖1 小时前
Linux 进程信号入门——从 Ctrl+C 到 kill
linux·开发语言·c++·笔记·学习