“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

相关推荐
派阿喵搞电子41 分钟前
在UI界面内修改了对象名,在#include “ui_mainwindow.h“没更新
c++·qt·ubuntu·ui
C++ 老炮儿的技术栈2 小时前
UDP 与 TCP 的区别是什么?
开发语言·c++·windows·算法·visual studio
wgslucky2 小时前
Dubbo报错:module java.base does not “opens java.lang“ to unnamed module
java·开发语言·dubbo
whyeekkk2 小时前
python打卡第48天
开发语言·python
DougLiang3 小时前
关于easyexcel动态下拉选问题处理
java·开发语言
mochensage3 小时前
CSP信奥赛C++常用系统函数汇总
c++·信奥
mochensage3 小时前
C++信息学竞赛中常用函数的一般用法
java·c++·算法
fpcc3 小时前
跟我学c++中级篇——多线程中的文件处理
c++
全职计算机毕业设计4 小时前
基于Java Web的校园失物招领平台设计与实现
java·开发语言·前端
5:004 小时前
云备份项目
linux·开发语言·c++