“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

相关推荐
1570925113425 分钟前
【无标题】
开发语言·python·算法
xieliyu.33 分钟前
MySQL 存储过程详解:概念、创建与删除全教程
开发语言·数据库·mysql
2zcode1 小时前
项目文档:基于MATLAB最小二乘支持向量机的睡眠分期智能监测系统设计与实现
开发语言·支持向量机·matlab
王维同学1 小时前
Credential Provider、Filter 与 PLAP 的 CLSID 枚举
c++·windows·安全·注册表
twcc_come1 小时前
安全策略配置实验报告
开发语言·php
2601_963870221 小时前
基于Python的晋江文学城热门作品数据分析与可视化
开发语言·python·数据分析
Carlgood-Minecraft2 小时前
随机分位系统破解版 (BPS)Version-B4.2
c++
其实防守也摸鱼2 小时前
Kimi K3深度测评:长文本之外的真实力
运维·开发语言·网络·人工智能·python·学习·安全
冻柠檬飞冰走茶2 小时前
PTA基础编程题目集 7-7 12-24小时制(C语言实现)
c语言·开发语言·数据结构·算法
梦幻通灵2 小时前
Java中finally失效的几种情况【持续更新】
java·开发语言