“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

相关推荐
剑穗挂着新流苏3124 分钟前
208_深度学习的鲁棒性之美:暂退法(Dropout)原理与实战
开发语言·pytorch·python·深度学习
小草cys11 分钟前
review202604032342
开发语言·php
一只小阿乐13 分钟前
js流式模式输出 函数模式使用
开发语言·javascript·ai·vue·agent·流式数据·node 服务
伯远医学14 分钟前
如何判断提取的RNA是否可用?
java·开发语言·前端·javascript·人工智能·eclipse·创业创新
搜狐技术产品小编202321 分钟前
端侧Python动态算法策略的部署与运行
开发语言·python
cch891824 分钟前
C++与PHP:7大核心差异全解析
java·开发语言
ID_1800790547341 分钟前
Python 采集转转二手商品详情:API 接口与爬虫实战全方案(2026 最新)
开发语言·爬虫·python
lifewange43 分钟前
JavaScript是什么
开发语言·javascript·ecmascript
环黄金线HHJX.44 分钟前
《Tuan(拼音字母)⇆团(Group)/&湍(Turbulence)/&双结构链路道/&文字、符号、语言/&源点设计、连接起:人类与自然+AICosmOS》
开发语言·人工智能·算法·编辑器
xyq20241 小时前
MongoDB 条件操作符
开发语言