“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

相关推荐
杜 硕4 小时前
从零开始的C++生活——第六讲——02
c++·算法·生活
Wang's Blog4 小时前
Java 项目实战:交友项目 - 保存访客记录
java·开发语言·交友
小超人诞生日记4 小时前
C++ STL 反向迭代器:从源码框架到适配器实现
c++·算法
青少儿编程课堂4 小时前
蓝桥杯青少组图形化 + 全国青少年信息素养大赛 + 电子学会Scratch考级:校园成语接龙大挑战解析
c++·python·算法·bfs·信息学竞赛
Raas1005 小时前
AI网关如何接入?MAI Gateway部署实操教程
java·开发语言·人工智能·gateway·ai网关·mai gateway·企业级产品
小贾要学习5 小时前
【C++后端开发项目】Reactor 模型 / C++ 仿写 muduo HTTP 服务器:让底层网络库真正跑起网页
linux·服务器·c++·http·网络编程·muduo·reactor模型
小小龙学IT5 小时前
Go 语言 pprof 性能剖析与调优深度解析:把“卡在哪“变成一张可执行的数据图
开发语言·后端·golang
starzy19905 小时前
Scala Set深度解析:为什么大数据开发离不开它?
大数据·开发语言·scala
熊猫钓鱼>_>6 小时前
三方库 NDK 原生模块跨平台适配与调试【鸿蒙心迹】
开发语言·华为·ai编程·harmonyos·鸿蒙·openharmony·鸿蒙心迹
A7bert7776 小时前
【MobileSAM部署至RK3588】环境适配→转换RKNN→开发板部署
c++·人工智能·深度学习·目标检测·ubuntu