“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

相关推荐
青少儿编程课堂13 小时前
2026青少儿信息素养大赛备赛指南!Python/Scratch/C++备考要点
开发语言·c++·python
旖-旎13 小时前
深搜练习(电话号码字母组合)(3)
c++·算法·力扣·深度优先遍历
AIFarmer13 小时前
【无标题】
开发语言·c++·算法
昇腾CANN13 小时前
TileLang-Ascend 算子性能优化方法与实操
开发语言·javascript·性能优化·昇腾·cann
John_ToDebug13 小时前
WebHostView 与 TabStrip 交互机制深度解析
c++·chrome·windows
沐知全栈开发14 小时前
ionic 手势事件详解
开发语言
lsx20240614 小时前
Bootstrap 按钮
开发语言
神仙别闹14 小时前
基于 Python 实现 BERT 的情感分析模型
开发语言·python·bert
禾叙_14 小时前
【langchain4j】结构化输出(六)
java·开发语言
NQBJT14 小时前
VS Code配置Python人工智能开发环境
开发语言·人工智能·vscode·python