“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 分钟前
【JAVA算法|hot100】堆类型题目详解笔记
java·开发语言·笔记
载数而行5207 分钟前
算法系列3之拓扑排序
c语言·数据结构·c++·算法·排序算法
天一生水water10 分钟前
LangChain的智能体教程
开发语言·人工智能·langchain·php·智慧油田
adore.96813 分钟前
2.21 oj基础89 90 91+U12B部分
开发语言·c++
feng_you_ying_li13 分钟前
data类的实现
c++
yyjtx13 分钟前
DHU上机打卡D28
开发语言·c++·算法
楼田莉子15 分钟前
CMake学习:CMake在二进制工程场景上应用
linux·c++·vscode·学习·软件构建
专注VB编程开发20年18 分钟前
C#,VB.NET如何用GPU进行大量计算,提高效率?
开发语言·c#·.net
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧19 分钟前
Jsoup: 一款Java的HTML解析器
java·开发语言·前端·后端·缓存·html
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧20 分钟前
JSP, MVC, El, JSTL, MAC
java·开发语言·mvc·mac·jsp