“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

相关推荐
江畔柳前堤1 天前
roLabelImg 详细安装教程
开发语言·人工智能·后端·云原生
Wang's Blog1 天前
Go-Zero 项目开发47:自研微服务框架的必要性与核心结构设计
开发语言·微服务·golang
白鸽(二般)1 天前
MinIO Java Client API
java·开发语言
hPw0eKIqD1 天前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
程序员爱德华1 天前
Python与C++:异同点对比
c++·python
临床数据科学和人工智能兴趣组1 天前
要使用 R Markdown,首先需要安装 R 和 RStudio,接着安装 rmarkdown 包
开发语言·数据挖掘·数据分析·r语言·r语言-4.2.1
Nebula嵌入式1 天前
【C语言】09-深入解析main函数
linux·c语言·开发语言·嵌入式
神罚天下ET1 天前
c# ACME client (补充)
开发语言·c#
小灰灰搞电子1 天前
Qt 实现魔法导航菜单源码分享
开发语言·qt
持敬chijing1 天前
Python概述
开发语言·python