“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

相关推荐
宋拾壹5 小时前
同时添加多个类目
android·开发语言·javascript
凡人叶枫6 小时前
Effective C++ 条款04:确定对象被使用前已先被初始化
java·linux·开发语言·c++·嵌入式开发
不想写代码的星星6 小时前
std::move 根本不移动,就像老婆饼里没有老婆
c++
redaijufeng6 小时前
C++雾中风景7:闭包
c++·算法·风景
小小龙学IT6 小时前
Go 语言后端开发:从并发模型到生产落地的工程实践
开发语言·后端·golang
ytttr8736 小时前
Qt 数字键盘实现
开发语言·qt
wearegogog1236 小时前
C# .NET 文件比较工具 WinForms
开发语言·c#·.net
再写一行代码就下班6 小时前
Cursor配置Java环境、创建Spring Boot项目的步骤
java·开发语言·spring boot
零陵上将军_xdr7 小时前
后端转全栈学习-Day5-JavaScript 基础-3
开发语言·javascript·学习
小欣加油7 小时前
leetcode287寻找重复数
数据结构·c++·算法·leetcode