“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

相关推荐
aini_lovee11 小时前
C#与倍福PLC(通过ADS协议)通信上位机源程序实现
开发语言·c#
fie888912 小时前
基于 MATLAB 的前景背景分割系统
开发语言·matlab
郝学胜-神的一滴12 小时前
Qt 入门 01-02: 开发环境搭建指南
开发语言·c++·qt·客户端
Languorous.12 小时前
C++数据结构高阶|布隆过滤器(Bloom Filter)深度解析:从原理到手写实现,面试高频考点全覆盖
数据结构·c++·面试
山河木马12 小时前
Emscripten 从 C/C++ 调用 JavaScript
前端·javascript·c++
TANGLONG22212 小时前
【C++】继承详解——基类/派生类、作用域、默认函数、菱形继承(超详细)
java·c语言·c++·经验分享·笔记·ajax
小侯不躺平.12 小时前
C++ Boost库【2】 --stringalgo字符串算法
linux·c++·算法
铅笔小新z13 小时前
【C语言】数据类型和变量
c语言·开发语言
code_whiter13 小时前
C++11(stack和queue)
开发语言·c++
最后一支迷迭香13 小时前
苹果的MacOS系统适合做Java开发吗
java·开发语言·macos