“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

相关推荐
xiaoye37082 小时前
Java 自动装箱 / 拆箱 原理详解
java·开发语言
ZTLJQ3 小时前
数据的基石:Python中关系型数据库完全解析
开发语言·数据库·python
夏霞3 小时前
c# signlar 客户端传递参数给服务端配置方法
开发语言·c#
迷藏4944 小时前
**发散创新:基于 Rust的开源权限管理系统设计与实战**在现代软件架构中,**权限控制**早已不
java·开发语言·rust·开源
2301_818419014 小时前
C++中的解释器模式变体
开发语言·c++·算法
爱学习的大牛1234 小时前
windows tcpview 类似功能 c++
c++
摇滚侠5 小时前
Java 项目《谷粒商城-1》架构师级Java 项目实战,对标阿里 P6-P7,全网最强,实操版本
java·开发语言
biter down5 小时前
C++11 统一列表初始化+std::initializer_list
开发语言·c++
ShineWinsu6 小时前
爬虫对抗:ZLibrary反爬机制实战分析技术文章大纲
c++
telllong6 小时前
BeeWare:Python原生移动应用开发
开发语言·python