“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

相关推荐
Java后端的Ai之路几秒前
01-React基础教程
开发语言·前端·python·react.js·前端框架
书生执笔画浮沉9 分钟前
Linux桌面端应用向鸿蒙PC迁移适配纪实
c++·qt·c·信创·海思·libc·ohos
我的xiaodoujiao11 分钟前
Django 基础知识详细图文教程 14-Django 表单定义与使用
开发语言·后端·python·django
(Charon)14 分钟前
【C++面试】单例模式:懒汉式与饿汉式的实现、区别与线程安全
开发语言·c++·面试
某不知名網友15 分钟前
ROS2入门:命令行启动节点与Launch程序
c++·机器人
anew___29 分钟前
《从零手写操作系统 (29):管道与重定向进阶——命名管道、Here Document与Shell语法扩展》
java·开发语言·前端·javascript·网络
小米里的大麦37 分钟前
C++ 移动语义
c++·后端
jimy142 分钟前
虚函数和 RTTI实现运行时多态
开发语言·c++
一个有温度的技术博主1 小时前
凌晨两点的死锁:当线程“互相等死“
开发语言·后端·场景
Είναι η κοπέλα1 小时前
llama.cpp 与 GGUF 格式:本地大模型的“裸引擎“
开发语言·人工智能·pytorch·python·conda