“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 小时前
LeetCode热题100 最长公共子序列
c++·算法·leetcode·动态规划
Bat U1 小时前
JavaEE|多线程初阶(七)
java·开发语言
谭欣辰1 小时前
C++ 排列组合完整指南
开发语言·c++·算法
橙子也要努力变强2 小时前
信号捕捉底层机制-机理篇2
linux·服务器·c++
foundbug9992 小时前
自适应滤除直达波干扰的MATLAB实现
开发语言·算法·matlab
盐焗鹌鹑蛋2 小时前
【C++】stack和queue类
c++
XDH_CS2 小时前
MySQL 8.0 安装与 MySQL Workbench 使用全流程(超详细教程)
开发语言·数据库·mysql
小短腿的代码世界3 小时前
Qt实时盈亏计算深度解析:从持仓数据到动态盈亏展示
开发语言·qt
小康小小涵3 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python