“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

相关推荐
风兮雨露8 分钟前
Java 从入门到精通,前端资料
java·开发语言·前端
£suPerpanda8 分钟前
AtCoder Beginner Contest 453
c++·算法
梅羽落10 分钟前
WIFI破解
开发语言·python
码不停蹄的玄黓11 分钟前
Java 频繁GC 完整排查流程
java·开发语言
凤山老林15 分钟前
73-Java ListIterator 接口
java·开发语言
Roy_Sashulin15 分钟前
灵杉Java编程平台与传统开发工具区别
java·开发语言
xxxxxue15 分钟前
Windows 通过 右键菜单 调用 Python 脚本
开发语言·windows·python·右键菜单
Wonderful U17 分钟前
Python+Django实战|校园二手闲置交易平台:从实名认证到交易闭环的完整校园电商解决方案
开发语言·python·django
listhi52019 分钟前
基于雅克比迭代法的方腔流动 MATLAB 实现
开发语言·matlab
小白学大数据21 分钟前
全站链接深度爬取:Python GUI 事件绑定 + 运行时动态过滤实现思路
开发语言·爬虫·python