“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

相关推荐
小邓的技术笔记6 分钟前
Python 入门:从“其他语言”到 Pythonic 思维的完整迁移手册
开发语言·python
艾莉丝努力练剑8 分钟前
【Linux线程】Linux系统多线程(二):线程的优缺点
linux·运维·服务器·c++·学习
yunn_9 分钟前
Qt 多线程
c++·qt
啥咕啦呛12 分钟前
跟着AI学java第4天:面向对象编程巩固
java·开发语言·人工智能
Yu_Lijing12 分钟前
基于C++的《Head First设计模式》笔记——MVC模式
c++·笔记·设计模式
聆风吟º12 分钟前
【C标准库】深入理解C语言memcmp函数:内存比较的利器
c语言·开发语言·库函数·memcmp
艾莉丝努力练剑14 分钟前
【Linux线程】Linux系统多线程(一):线程概念
java·linux·运维·服务器·开发语言·学习·线程
低保和光头哪个先来15 分钟前
Axios 近期安全版本
开发语言·前端·javascript·前端框架
派带星-15 分钟前
基于 C++ 的第三方 SDK 封装实践(ASR + 短信服务)
c++·ide·macos
zzwq.19 分钟前
深入理解Python闭包与装饰器:从入门到进阶
开发语言·python