“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

相关推荐
bai_lan_ya2 分钟前
嵌入式linux学习--makefile的使用以及通用解析
开发语言·前端·javascript
tankeven3 分钟前
HJ100 等差数列
c++·算法
waves浪游3 分钟前
库制作与原理(上)
linux·运维·服务器·开发语言·c++
ADDDDDD_Trouvaille3 分钟前
2026.2.22——OJ98-100题
c++·算法
闻缺陷则喜何志丹7 分钟前
【差分数组】P9166 [省选联考 2023] 火车站|普及+
数据结构·c++·洛谷·差分数组
27669582927 分钟前
微博评论采集
开发语言·python·微博·微博评论·微博评论采集
tankeven8 分钟前
HJ99 自守数
c++·算法
山北雨夜漫步10 分钟前
MQ消息队列
java·开发语言
wjs202415 分钟前
Maven 项目模板
开发语言