“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

相关推荐
yong9990几秒前
基于MATLAB的雷达数字信号处理
开发语言·matlab·信号处理
SilentSamsara1 分钟前
HTTP 客户端实战:httpx/重试/限速/连接池/中间件设计
开发语言·网络·python·http·青少年编程·中间件·httpx
Hall_IC1 分钟前
LSM6DS3TR-C现货询价丨粤科源兴ST代理商,专业FAE技术支持
c++
进击的荆棘3 分钟前
优选算法——队列+宽搜
数据结构·c++·算法·leetcode·bfs·队列
Irissgwe4 分钟前
STL简介
c++·stl
江屿风7 分钟前
C++OJ题经验总结(竞赛)4
开发语言·c++·笔记·算法·dp·双指针
Deep-w7 分钟前
【MATLAB】微电网四DG逆变器下垂策略与分布式MPC协同控制仿真分析
开发语言·分布式·算法·matlab
酉鬼女又兒7 分钟前
零基础入门计算机网络:定义、分类与核心性能指标
开发语言·计算机网络·考研·青少年编程·职场和发展·php
码上有光7 分钟前
c++: 继承(下)
android·java·c++·多继承·菱形继承·虚继承
AI玫瑰助手12 分钟前
Python函数:可变参数(星号args与双星号kwargs)详解
android·开发语言·python