“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

相关推荐
Escalating_xu5 小时前
【C++ string 上篇】从字符串基础到容量管理、迭代器与经典算法题
java·c++·算法
mayaairi5 小时前
JS DOM属性操作完全指南:内容、样式与自定义属性
开发语言·前端·javascript
avi91115 小时前
Threejs新版本后glb导出提示.x问题GLTFExporter,替代3dmax
开发语言·前端·javascript·threejs·glb·gltfexporter
啦啦啦啦啦zzzz5 小时前
ET和LT详解
linux·运维·服务器·网络·c++·网络编程
qq762118225 小时前
windows Qt mingw 编译libzip
开发语言·windows·qt
曹牧5 小时前
Java:Java 数组转 List
java·开发语言·windows
skr爱码士5 小时前
10_Qt Designer 与 UI 文件(.ui 原理、uic 编译、动态加载)
c++·qt·ui·客户端
工业一体机老司机6 小时前
Python实现工业一体机OPC-UA通信:从SDK选型到数据采集实战
开发语言·python·单片机
IT爱学堂6 小时前
QT原理与源码分析可以学到什么 QT视频课程 QT课程推荐 最新推荐
开发语言·qt
wuyk5556 小时前
Python 零基础入门第七章:字典 Dict
开发语言·python