“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

相关推荐
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧2 小时前
C++学习:基础知识的掌握
c++·visualstudio
wuyk5553 小时前
第2章:六步换相原理全解+STM32工程实战
c语言·开发语言·stm32·单片机·嵌入式硬件
hey_sml3 小时前
JAVA每日一学---CompletableFuture中thenApply与thenCompose区别详解
java·开发语言
萧瑟余晖4 小时前
Java深入解析篇十七之SpringCloud
java·开发语言
ttod_qzstudio5 小时前
Java 常用语法极简通关(五):类与对象——字段、方法、构造器、this 与 static
java·开发语言·python
萧瑟余晖6 小时前
Java深入解析篇十七之Spring Security
java·开发语言·spring
C++ 老炮儿的技术栈8 小时前
从 Qt Designer 属性编辑器的层级可以看到继承链
c语言·数据库·c++·qt·sqlite·visual studio
new_zhou9 小时前
C++ 项目 AI 协作指南(Windows / MSVC 环境)
c++·人工智能·windows
二十雨辰9 小时前
[Java]-Spring面试题
java·开发语言
_oP_i9 小时前
python 后缀 mjs文件
开发语言·python