V2EX  ›  英汉词典
Enqueued related words: Nullpointer, Nullability, Undefined Behavior

Nullptr

释义 Definition

nullptr:C++中的关键字,表示空指针常量,用于明确表示“指向无效地址的指针值”。常用于初始化指针、与指针比较、或表示“没有对象/没有资源”。(在C++11引入,用来替代容易产生歧义的 NULL/0。)

发音 Pronunciation

/ˈnʌlˌpɔɪntər/

例句 Examples

I set the pointer to nullptr.
我把这个指针设为 nullptr。

If the function returns nullptr, the caller should handle the error and avoid dereferencing the pointer.
如果函数返回 nullptr,调用方应处理错误并避免对该指针解引用。

词源 Etymology

null(“空、无效”)和 pointer(“指针”)组合而来,字面意思是“空指针”。C++11正式引入 nullptr,目的是提供一个类型更明确的空指针字面量,减少与整数常量混用导致的重载解析与类型转换问题。

相关词 Related Words

文学与作品 Literary Works

  • The C++ Programming Language(Bjarne Stroustrup)中在讲解现代C++特性与类型系统时会涉及 nullptr
  • *Effective Modern C++*(Scott Meyers)在“优先使用 nullptr 而非 0/NULL”等建议中多次使用 nullptr
  • C++ Primer(Lippman, Lajoie, Moo)在介绍C++11及指针相关章节中常出现 nullptr
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2775 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 16ms · UTC 04:16 · PVG 12:16 · LAX 20:16 · JFK 23:16
♥ Do have faith in what you're doing.