“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

相关推荐
郑州光合科技余经理14 小时前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo12315 小时前
matlab画图工具
开发语言·matlab
dustcell.15 小时前
haproxy七层代理
java·开发语言·前端
norlan_jame15 小时前
C-PHY与D-PHY差异
c语言·开发语言
哇哈哈202115 小时前
信号量和信号
linux·c++
多恩Stone16 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ40220549616 小时前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月16 小时前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
蜡笔小马16 小时前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
m0_5312371716 小时前
C语言-数组练习进阶
c语言·开发语言·算法