“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

相关推荐
灯澜忆梦3 分钟前
【面向对象编程c++】| 数组与函数
java·数据结构·c++
我命由我1234511 分钟前
Android 广播 - 组件通信
android·java·开发语言·android studio·android jetpack·android-studio·android runtime
前端 贾公子13 分钟前
LangGraph == 图的状态(State)管理 (中)
开发语言·数据库·python
起个名字费劲死了22 分钟前
VisionMaster 十二点标定+单点抓取
c++·visionmaster
李福春26 分钟前
斗破Google ADK Java苍穹-第2境斗者-凝旋筑基-Java环境
java·开发语言·gemini·llmagent·深圳同盟·腾讯云架构师技术同盟·adk java
老王爱玩车1 小时前
预处理详解
c语言·开发语言·学习
灯澜忆梦1 小时前
【Go Zap 日志库】#1 |快速上手 + 配置详解
开发语言·后端·golang
a努力。1 小时前
四维解析Agent记忆架构:从零实战LangGraph长期记忆
java·开发语言·数据库
Wang's Blog1 小时前
Java 项目部署之 Docker工具快速入门: Docker Compose 初识与安装
java·开发语言·docker
niucloud-admin2 小时前
JAVA V6 多商户商城 开发文档——项目启动
java·开发语言·python