“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

相关推荐
王有品20 分钟前
python之爬虫入门实例
开发语言·爬虫·python
一水鉴天23 分钟前
为AI聊天工具添加一个知识系统 之135 详细设计之76 通用编程语言 之6
开发语言·人工智能·架构
m0_7482475535 分钟前
数据库系统架构与DBMS功能探微:现代信息时代数据管理的关键
java·开发语言·数据库
环能jvav大师1 小时前
Electron桌面应用开发:自定义菜单
开发语言·前端·javascript·windows·electron
一水鉴天1 小时前
为AI聊天工具添加一个知识系统 之136 详细设计之77 通用编程语言 之7
开发语言·人工智能·架构
一只小小汤圆1 小时前
c++ std::tuple用法
开发语言·c++
Jelena157795857921 小时前
爬虫与翻译API接口的完美结合:开启跨语言数据处理新纪元
开发语言·数据库·爬虫
柠石榴1 小时前
【练习】【二叉树】力扣热题100 102. 二叉树的层序遍历
c++·算法·leetcode·二叉树
gyc27272 小时前
快速熟悉JavaScript
开发语言·前端·javascript
越甲八千2 小时前
C++海康相机DEMO
开发语言·c++·数码相机