“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

相关推荐
猫墨*18 小时前
springboot3、knife4j-openapi3配置动态接口版本管理
java·开发语言
weixin_5316518118 小时前
Python 渐进式学习指南
开发语言·windows·python
weixin_6495556718 小时前
C语言程序设计第四版(何钦铭、颜晖)第八章指针之在数组中查找指定元素
c语言·开发语言
add45a18 小时前
C++中的原型模式
开发语言·c++·算法
代码s贝多芬的音符18 小时前
Android NV21 转 YUV 系列格式
android·开发语言·python
2401_8442213218 小时前
C++类型推导(auto/decltype)
开发语言·c++·算法
2201_7538777918 小时前
高性能计算中的C++优化
开发语言·c++·算法
无限进步_18 小时前
深入解析C++容器适配器:stack、queue与deque的实现与应用
linux·开发语言·c++·windows·git·github·visual studio
2501_9454251518 小时前
分布式系统容错设计
开发语言·c++·算法
阿成学长_Cain18 小时前
Linux 命令:ldconfig —— 动态链接库管理命令
java·开发语言·spring