“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

相关推荐
ZIM学编程26 分钟前
「学长有话说」作为一个大三学长,我想对大一计算机专业学生说这些!
java·c语言·数据结构·c++·python·学习·php
maizeman12631 分钟前
用R语言生成指定品种与对照的一元回归直线(含置信区间)
开发语言·回归·r语言·置信区间·品种测试
代码AC不AC39 分钟前
【C++】哈希表封装实现 unordered_map 和 unordered_set
c++·unordered_map·unordered_set·哈希表封装
脚踏实地的大梦想家1 小时前
【Go】P17 Go语言并发编程核心:深入理解 Goroutine (从入门到实战)
java·开发语言·golang
初学小白...1 小时前
线程同步机制及三大不安全案例
java·开发语言·jvm
子枫秋月2 小时前
单链表实现全解析
c语言·数据结构·c++
用坏多个鼠标2 小时前
Nacos和Nginx集群,项目启动失败问题
java·开发语言
满天星83035773 小时前
【C++】右值引用和移动语义
开发语言·c++·redis·visual studio
消失的旧时光-19433 小时前
c语言 内存管理(malloc, calloc, free)
c语言·开发语言
歪歪1003 小时前
在C#中除了按属性排序,集合可视化器还有哪些辅助筛选的方法?
开发语言·前端·ide·c#·visual studio