“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

相关推荐
147API几秒前
Claude Tag 进入 Slack 后,团队智能体需要哪些任务与审计字段
java·开发语言·数据库
熬夜苦读学习9 分钟前
QT_信号和槽
开发语言·qt
代码雕刻家12 分钟前
编程语法细节
java·c语言·开发语言
j7~13 分钟前
【C++】C++ 继承全解析:从基本语法到菱形继承的底层原理
开发语言·c++·继承·组合·虚继承·#暑假·七月创作之星博客挑战赛
数行拙笔16 分钟前
C++客户端---String类型
开发语言·c++·bootstrap
影寂ldy23 分钟前
C# Task 进阶:WaitAll / WaitAny / WhenAll / WhenAny
开发语言·c#
左左右右左右摇晃34 分钟前
手写Tomcat原理整理
java·开发语言·笔记·tomcat
孫治AllenSun37 分钟前
【JVM】四大引用类型分析
java·开发语言·jvm
看-是灰机38 分钟前
使用go语言实现对接
linux·开发语言·后端·docker·语言模型·golang·飞书
草莓熊Lotso39 分钟前
【Linux网络】深入理解Linux IO多路复用:从本质到select服务器实战
linux·运维·服务器·c语言·网络·数据库·c++