“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 小时前
推荐个C++高性能内存分配器
开发语言·c++·内存分配
liu****1 小时前
27.epoll(三)
服务器·开发语言·网络·tcp/ip·udp
福尔摩斯张1 小时前
Axios源码深度解析:前端请求库设计精髓
c语言·开发语言·前端·数据结构·游戏·排序算法
zephyr052 小时前
深入浅出C++多态:从虚函数到动态绑定的完全指南
开发语言·c++
Chef_Chen2 小时前
数据科学每日总结--Day25--区块链
开发语言·php
L-李俊漩2 小时前
MMN-MnnLlmChat 启动顺序解析
开发语言·python·mnn
小镇学者2 小时前
【PHP】PHP WebShell(网页木马)分析
android·开发语言·php
q***69772 小时前
java进阶1——JVM
java·开发语言·jvm
沐知全栈开发2 小时前
PHP $_GET 变量详解
开发语言