“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

相关推荐
z落落4 分钟前
C# 接口 interface (多接口实现、类+接口、成员重名)
java·开发语言
王老师青少年编程15 分钟前
信奥赛C++提高组csp-s之搜索进阶(迭代加深IDDFS)
c++·csp·信奥赛·csp-s·提高组·iddfs·埃及分数
liulilittle35 分钟前
我从 BBRv1 到 KCC 的思考
网络·c++·tcp/ip·计算机网络·tcp·bbr·通信
落羽的落羽37 分钟前
【项目】JsonRpc框架——开发实现1(细节功能、字段定义、抽象层、具象层)
linux·服务器·网络·c++·人工智能·算法·机器学习
handler011 小时前
【算法】并查集(普通/扩展/带权)模板与例题
数据结构·c++·笔记·算法·c·图论·查并集
知识的宝藏1 小时前
Xpaht self::div 轴语法
开发语言
keykey6.1 小时前
卷积神经网络(CNN):让AI学会“看“
开发语言·人工智能·深度学习·机器学习
IsJunJianXin1 小时前
谷歌搜索cookie NID逆向生成
开发语言·python·google搜索·sgss·nid-cookie·算法生成nid·google-cookie
weikecms1 小时前
美团霸王餐报名API接口
java·开发语言
繁星蓝雨2 小时前
C++中对比pragma once和ifndef的使用区别
开发语言·c++·ifndef·头文件·pragma once