“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

相关推荐
动能小子ohhh11 分钟前
DocForge平台的设计与开发--文件上传接口的实现
开发语言·人工智能·python·langchain·ocr·fastapi
满天星830357714 分钟前
【Qt】信号和槽(二) (自定义信号和槽)
开发语言·数据库·qt
王老师青少年编程34 分钟前
信奥赛C++提高组csp-s之搜索进阶(记忆化搜索案例实践3)
c++·记忆化搜索·方格取数·csp·信奥赛·csp-s·提高组
超哥--41 分钟前
B站视频内容智能分析系统(三):B站视频自动采集
java·开发语言·音视频·ai编程
夏语灬44 分钟前
cryptography:Python 密码学标准库的终极选择
开发语言·python·密码学
Jun6261 小时前
QT(19)-VISA控制仪器
开发语言·qt
ANnianStriver1 小时前
PetLumina 07 — 宠物管理升级与 JavaScript 大数精度修复
开发语言·javascript·ai编程·宠物
Titan20242 小时前
Linux动静态库
linux·服务器·c++
辣椒思密达2 小时前
Python公开数据采集实战:如何解决请求高频拦截与Session会话中断问题
开发语言·python
j_xxx404_2 小时前
MySQL表操作硬核解析:从 CREATE TABLE 到磁盘文件、ALTER TABLE 与 DDL 风险
运维·服务器·数据库·c++·mysql·adb·ai