“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

相关推荐
tankeven3 分钟前
HJ127 小红的双生串
c++·算法
不光头强7 分钟前
Java中的异常
java·开发语言
Coding茶水间9 分钟前
基于深度学习的管道缺陷检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
开发语言·人工智能·深度学习·yolo·机器学习
shamalee11 分钟前
MS SQL Server partition by 函数实战二 编排考场人员
java·服务器·开发语言
listhi52014 分钟前
基于MATLAB的汽车电动助力转向系统(EPS)转向特性分析
开发语言·matlab·汽车
C++chaofan21 分钟前
JUC 并发编程:对可见性、有序性与 volatile的理解
java·开发语言·spring·java-ee·juc·synchronized·
csbysj202024 分钟前
Django ORM - 单表实例
开发语言
XiYang-DING25 分钟前
【Java SE】双亲委派模型
java·开发语言
阿阿阿阿里郎28 分钟前
ROS2快速入门--C++基础
开发语言·c++·算法
free-elcmacom30 分钟前
C++<x>new和delete
开发语言·c++·算法