“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

相关推荐
17(无规则自律)几秒前
Leetcode第六题:用 C++ 解决三数之和
c++·算法·leetcode
赵谨言2 分钟前
基于YOLOv5的火灾检测研究是当前计算机视觉和消防安全领域的重要研究方向
大数据·开发语言·经验分享·python
前端 贾公子4 分钟前
@uni-helper 社区:让 uni-app 拥抱 ESM 时代
开发语言·前端·javascript
wengqidaifeng5 分钟前
备战蓝桥杯----C/C++组 (一)所需C++基础知识(上)
c语言·数据结构·c++·蓝桥杯
弈风千秋万古愁6 分钟前
常见配置文件-AI辅助
开发语言·python
tankeven7 分钟前
HJ126 小红的正整数计数
c++·算法
不知名。。。。。。。。7 分钟前
仿muduo库实现高并发服务器-----Channel模块 和 Poller模块
开发语言·前端·javascript
Singe.Chen9 分钟前
C# 配置文件加密解密:最简便的实现方案
开发语言·网络协议·c#·信息与通信
花间相见10 分钟前
【JAVA基础01】——类和对象
java·开发语言·python
●VON10 分钟前
【鸿蒙PC】在 HarmonyOS 上跑 Electron?手把手教你搞定桌面欢迎页!(Mac版)
开发语言·macos·华为·electron·电脑·harmonyos