“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

相关推荐
持力行5 小时前
从C struct到C++中的class
c语言·c++
meilindehuzi_a6 小时前
从零理解并实现 RAG:用 LangChain.js 构建语义检索问答系统
开发语言·javascript·langchain
风流 少年6 小时前
Julia
开发语言·julia
江畔柳前堤6 小时前
GO01-Go 语言与主流编程语言深度对比
开发语言·人工智能·后端·微服务·云原生·golang·go
:-)7 小时前
算法-归并排序
java·开发语言·数据结构·算法·排序算法
GIS阵地8 小时前
QgsRasterDataProvider 完整详解(QGIS 3.40.13 C++)
开发语言·c++·qt·开源软件·qgis
yaoxin5211239 小时前
462. Java 反射 - 获取声明类与封闭类
java·开发语言·python
阿里嘎多学长9 小时前
2026-07-14 GitHub 热点项目精选
开发语言·程序员·github·代码托管
charlie11451419110 小时前
Cinux: 为大内核铺路
开发语言·c++·操作系统·现代c++
2501_9142459310 小时前
C语言设计模式详解:从理论到实践的完整指南
c语言·开发语言·设计模式