“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

相关推荐
xlq223222 小时前
22.多态(上)
开发语言·c++·算法
666HZ6662 小时前
C语言——高精度加法
c语言·开发语言·算法
星释2 小时前
Rust 练习册 100:音乐音阶生成器
开发语言·后端·rust
D_evil__2 小时前
[C++高频精进] 并发编程:线程基础
c++
风生u3 小时前
go进阶语法
开发语言·后端·golang
666HZ6663 小时前
C语言——黑店
c语言·开发语言
Gomiko3 小时前
JavaScript基础(八):函数
开发语言·javascript·ecmascript
〝七夜5693 小时前
JVM内存结构
java·开发语言·jvm
初级炼丹师(爱说实话版)3 小时前
JAVA泛型作用域与静态方法泛型使用笔记
java·开发语言·笔记
Mr_WangAndy3 小时前
C++17 新特性_第二章 C++17 语言特性_std::any和string_view
c++·string_view·c++40周年·c++17新特性·c++新特性any