“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

相关推荐
归去来?7 分钟前
Python 常用优雅写法
开发语言·python
devilnumber18 分钟前
Java 30 组高频技术 / 知识点多角度对比
java·开发语言
何以解忧,唯有..26 分钟前
Python 异常处理完全指南:从基础到高级实践
开发语言·前端·python
啦啦啦啦啦zzzz27 分钟前
时间轮定时器
linux·服务器·网络·c++·定时器
gugucoding43 分钟前
57. 【Java】日志框架:SLF4J与Logback
java·开发语言·logback
此生决int1 小时前
深入理解C++系列(15)——AVL树
开发语言·c++
一只旭宝1 小时前
预约系统版本2(pyhton+flask可视化版本)
服务器·数据库·c++·笔记·python·flask
筱璦1 小时前
PHP+ VUE3机构级股票分仓管理交易系统源码可出
开发语言·php·vue3·量化·股票分仓
爱奥尼欧1 小时前
10.C++ string 实现详解
java·开发语言·c++
骇客野人1 小时前
Java分布式任务调度方案(完整落地指南)
java·开发语言·分布式