“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

相关推荐
wjs202411 分钟前
Eclipse 关闭项目详解
开发语言
沐知全栈开发13 分钟前
《隐藏(Hide)》
开发语言
_OP_CHEN18 分钟前
Linux网络编程:(八)GCC/G++ 编译器完全指南:从编译原理到实战优化,手把手教你玩转 C/C++ 编译
linux·运维·c++·编译和链接·gcc/g++·编译优化·静态链接与动态链接
lkbhua莱克瓦2418 分钟前
Java基础——方法
java·开发语言·笔记·github·学习方法
catchadmin30 分钟前
PHP 依赖管理器 Composer 2.9 发布
开发语言·php·composer
范纹杉想快点毕业1 小时前
《嵌入式开发硬核指南:91问一次讲透底层到架构》
java·开发语言·数据库·单片机·嵌入式硬件·mongodb
毕设源码-邱学长1 小时前
【开题答辩全过程】以 基于Python的Bilibili平台数据分析与可视化实现为例,包含答辩的问题和答案
开发语言·python·数据分析
芝麻馅汤圆儿1 小时前
c文件编译
c语言·开发语言
大锦终1 小时前
【动规】背包问题
c++·算法·动态规划
千疑千寻~1 小时前
【Qt】QT的程序打包
开发语言·qt