“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

相关推荐
你不是我我2 小时前
【Java 开发日记】HTTP3 性能更好,为什么内网微服务依然多用 HTTP2?HTTP2 内网优势是什么?
java·开发语言·微服务
tjl521314_213 小时前
04C++ 名称空间(Namespace)
开发语言·c++
ximu_polaris3 小时前
设计模式(C++)-行为型模式-备忘录模式
c++·设计模式·备忘录模式
赏金术士3 小时前
Kotlin 数据流与单双向绑定
android·开发语言·kotlin
逻辑驱动的ken4 小时前
Java高频面试场景题25
java·开发语言·深度学习·面试·职场和发展
AI人工智能+电脑小能手5 小时前
【大白话说Java面试题】【Java基础篇】第32题:Java的异常处理机制是什么
java·开发语言·后端·面试
無限進步D7 小时前
Java 面向对象高级 接口
java·开发语言
tankeven7 小时前
C++ 智能指针
c++
两年半的个人练习生^_^8 小时前
Java日志框架和使用、日志记录规范
java·开发语言·开发规范
杨凯凡8 小时前
【032】排查入门:jstack、heap dump、Arthas 初识
java·开发语言·后端