“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

相关推荐
是梦终空11625 分钟前
C++中的职责链模式变体
开发语言·c++·算法
mjhcsp29 分钟前
C++遗传算法(Genetic Algorithm,GA):进化式全局优化的核心解析
开发语言·c++
仰泳的熊猫29 分钟前
题目2270:蓝桥杯2016年第七届真题-四平方和
c++·算法·蓝桥杯
Aaswk1 小时前
蓝桥杯2025年第十六届省赛真题(更新中)
c语言·数据结构·c++·算法·职场和发展·蓝桥杯
燕山罗成2 小时前
JAVA多线程基础
java·开发语言
王老师青少年编程2 小时前
信奥赛C++提高组csp-s之数论基础专题课:欧拉函数和欧拉定理2(编程案例实践)
c++·数论·欧拉函数·信奥赛·欧拉定理·csp-s·提高组
Yvonne爱编码2 小时前
JAVA数据结构 DAY7-二叉树
java·开发语言·数据结构
En^_^Joy2 小时前
JavaScript入门指南:从零到精通
开发语言·javascript
总斯霖2 小时前
P15445永远在一起!题解(月赛T2)
数据结构·c++·算法·深度优先
于先生吖2 小时前
2026 新版 Java 同城上门家政服务系统源码 完整可运营
java·开发语言