“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

相关推荐
大前端下的小角色8 分钟前
UE5.6 Cesium 插件编译踩坑记录(UE 5.6 + MSVC 14.38 + CMake 3.31)
c++
lzhdim14 分钟前
SharpCompress:跨平台的 C# 压缩与解压库
开发语言·c#
嘿嘿嘿x319 分钟前
Linux记录过程
linux·开发语言
默 语27 分钟前
Records、Sealed Classes这些新特性:Java真的变简单了吗?
java·开发语言·python
止观止28 分钟前
拥抱 ESNext:从 TC39 提案到生产环境中的现代 JS
开发语言·javascript·ecmascript·esnext
卷心菜狗38 分钟前
Python进阶-深浅拷贝辨析
开发语言·python
时寒的笔记39 分钟前
js逆向7_案例惠nong网
android·开发语言·javascript
Evand J1 小时前
【MATLAB例程】基于低精度IMU、GNSS的UAV初始航向(三维角度)校准的仿真,包含卡尔曼滤波、惯导解算与校正
开发语言·matlab·gnss·imu·卡尔曼滤波
feng_you_ying_li1 小时前
c++之哈希表的介绍与实现
开发语言·c++·散列表
网域小星球1 小时前
C 语言从 0 入门(十四)|文件操作:读写文本、保存数据持久化
c语言·开发语言·文件操作·fopen·fprintf