“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

相关推荐
myloveasuka3 小时前
Java与C++多态访问成员变量/方法 对比
java·开发语言·c++
2301_821700533 小时前
C++编译期多态实现
开发语言·c++·算法
奥地利落榜美术生灬3 小时前
c++ 锁相关(mutex 等)
开发语言·c++
xixihaha13243 小时前
C++与FPGA协同设计
开发语言·c++·算法
重庆小透明3 小时前
【java基础篇】详解BigDecimal
java·开发语言
ID_180079054733 小时前
模拟1688商品详情的Python API实现,返回符合风格的JSON数据
开发语言·python·json
小小怪7504 小时前
C++中的函数式编程
开发语言·c++·算法
金山几座4 小时前
C#学习记录-事件
开发语言·学习·c#
小杍随笔4 小时前
【Rust 语言编程知识与应用:基础数据类型详解】
开发语言·后端·rust
Yupureki4 小时前
《MySQL数据库基础》1. 数据库基础
c语言·开发语言·数据库·c++·mysql·oracle·github