“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

相关推荐
玖釉-1 分钟前
nvpro_core2 源码与架构解析:NVIDIA Vulkan 图形开发基础框架
c++·windows·图形渲染
秋田君17 分钟前
QT_一个UDP通信程序(单播+广播)
开发语言·qt·udp
qq_225891746635 分钟前
基于Flask的空气质量监测与预测分析系统
开发语言·后端·python·信息可视化·django·flask
lhldsg1 小时前
社区健身系统开发实战:从需求分析到落地部署全流程指南
java·开发语言·小程序·需求分析
李高钢1 小时前
C# WPF Prism 进阶(三):导航(Navigation)深入
开发语言·c#·wpf
冯汉栩1 小时前
Swift Control DashLineView(虚线)
开发语言·ios·swift
笨鸟先飞的橘猫1 小时前
c++游戏后端开源框架学习——wukong(十、lua热更新)
c++·游戏·开源
覆东流1 小时前
4.Java运算符与表达式
java·开发语言·后端
我变成萤火虫1 小时前
2026 ICPC沈阳邀请赛Vp补题
数据结构·c++·算法·贪心算法·stl·排序算法·动态规划
SomeB1oody1 小时前
【RustyML入门】5.1. 回归指标
开发语言·后端·机器学习·rust·教程