“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

相关推荐
柒.梧.3 分钟前
Java集合核心知识点深度解析:数组与集合区别、ArrayList原理及线程安全问题
java·开发语言·python
Qt学视觉3 分钟前
AI3-PaddleOCR搭建环境1
c++·人工智能·opencv·ocr·paddlepaddle
0 0 04 分钟前
洛谷P4427 [BJOI2018] 求和 【考点】:树上前缀和
开发语言·c++·算法·前缀和
web3.08889995 分钟前
使用PHP采集数据的完整技术文章,涵盖多种场景和最佳实践
开发语言·php
柒.梧.11 分钟前
Java基础高频面试题(含详细解析+易错点,面试必看)
java·开发语言·面试
Darkwanderor11 分钟前
数据结构——树状数组和在线、离线操作
数据结构·c++·树状数组·离线操作
佩奇大王12 分钟前
P593 既约分数
java·开发语言·算法
polaris063019 分钟前
Java集合进阶
java·开发语言
AsDuang25 分钟前
Python 3.12 MagicMethods - 49 - __imatmul__
开发语言·python
小温冲冲37 分钟前
如何在Visual Studio中创建QML工程
c++·qt·visual studio