“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

相关推荐
码匠许师傅31 分钟前
【设计模式精讲】14.外观模式(Facade)
c++·设计模式·uml·外观模式
卢锡荣1 小时前
国产PD3.1全集成Type-C管控芯片LDR6020P
c语言·开发语言
Freak嵌入式1 小时前
Pico UART 数据收发实战:硬件配置、MicroPython 编程
java·开发语言·单片机·嵌入式硬件·生活
Casual1 小时前
【网络基础进阶】:看懂子网划分与 VLAN
开发语言·网络·php
cfm_29142 小时前
线程池阻塞队列
java·开发语言
xxwxx__2 小时前
C++ list 深度解析:从使用原理到模拟实现
开发语言·c++·list
Chester_19992 小时前
CSP202303C.LDAP
开发语言·c++·蓝桥杯·stl
奋斗吧程序媛3 小时前
CSV文件导入功能
开发语言·javascript·ecmascript
evans在进步3 小时前
Java 常用设计模式(二):装饰器、适配器、责任链、模板方法、策略与观察者
java·开发语言·设计模式
小雨笙笙3 小时前
C语言:指针
c语言·开发语言