“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

相关推荐
阿kun要赚马内1 小时前
C++中的Windows API双缓冲技术
c++
WBluuue7 小时前
Codeforces 1078 Div2(ABCDEF1)
c++·算法
geovindu7 小时前
python: Memento Pattern
开发语言·python·设计模式·备忘录模式
学无止境_永不停歇7 小时前
十、C++多态
开发语言·c++
寻星探路8 小时前
【JVM 终极通关指南】万字长文从底层到实战全维度深度拆解 Java 虚拟机
java·开发语言·jvm·人工智能·python·算法·ai
Aric_Jones8 小时前
JavaScript 从入门到精通:完整语法指南
开发语言·javascript·ecmascript
岱宗夫up8 小时前
FastAPI入门(上篇):快速构建高性能Python Web API
开发语言·前端·python·fastapi
老歌老听老掉牙8 小时前
QT开发踩坑记:按钮点击一次却触发两次?深入解析信号槽自动连接机制
c++·qt
Dxy12393102168 小时前
中文乱码恢复方案
开发语言·python
橘色的喵8 小时前
现代 C++17 相比 C 的不可替代优势
c语言·c++·现代c++·c++17