“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

相关推荐
暖阳华笺4 分钟前
【高频考点】回溯(暴力搜索)
数据结构·c++·算法·回溯法
hunterkkk(c++)4 分钟前
学习dijkstra算法(c++)
c++·学习·算法
wb0430720113 分钟前
外卖大战——从阿明的“3 秒生死线“,看系统性能优化的全链路方法论
开发语言·性能优化·架构·php
小的~~13 分钟前
Java线程及线程池的相关的问题
java·开发语言·多线程
c++之路14 分钟前
Linux 下 C++ 开发环境搭建
linux·运维·c++
CTA终结者17 分钟前
Python 写期货自动交易:行情下单与成交回报怎么组织
开发语言·python·区块链
TE-茶叶蛋24 分钟前
Next.js中App Router 全部特殊文件一览
开发语言·javascript·网络
红藕香残玉簟秋33 分钟前
【Rust学习】windows安装rust
开发语言·学习·rust
弹简特41 分钟前
【零基础学Python】08-Python面向对象之封装、多态和函数进阶
开发语言·python
人道领域44 分钟前
一篇文章解决Codex的安装,实操一遍过
java·开发语言·codex