“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

相关推荐
小王C语言8 分钟前
【8.进行接口测试】:通过 curl 进行接口自动化测试 / 通过 python 程序进行接口自动化测试
网络·c++
易筋紫容1 小时前
创建型模式:对象的诞生艺术
开发语言·前端·javascript
888CC++1 小时前
C++ 快速学习指南:从入门到进阶的实战路线
开发语言·c++
小小晓.1 小时前
C++记:函数
开发语言·c++·算法
牡丹雅忻11 小时前
AES 加密模式演进:从 ECB、CBC 到 GCM 的 C# 深度实践
java·开发语言·c#
连续讨伐2 小时前
php小结
开发语言·php
进击的程序猿~2 小时前
Go 并发底层原理面试学习指南
开发语言·面试·golang
脚踏实地皮皮晨2 小时前
002002002_DepandencyObject类2
开发语言·windows·算法·c#·visual studio
驱动小百科2 小时前
Windows运行库合集下载 VC++、DirectX、.NET运行库安装教程
c++·windows·.net·windows运行库合集下载·windows运行库安装
练习时长一年2 小时前
@SneakyThrows注解
开发语言