C++ 中的关键词和标识符


2022年7月20日, Learn eTutorial
1997

C++ 关键字

具有特定含义的预定义词被称为关键字。例如:


int price;

 

在上面的示例中,price 是一个整数类型的变量,由关键字 int 指示。

C++ 中使用的关键字列表。我们知道 C++ 是一种大小写敏感的语言,所有关键字都应该用小写字母书写。

alignas decltype namespace struct
alignof default new switch
and delete noexcept template
and_eq do not this
asm double not_eq thread_local
auto dynamic_cast nullptr throw
bitand else operator true
bitor enum or try
bool explicit or_eq typedef
break export private typeid
case extern protected typename
catch false public union
char float register unsigned
char16_t for reinterpret_cast using
char32_t friend return virtual
class goto short void
compl if signed volatile
const inline sizeof wchar_t
constexpr int static while
const_cast long static_assert xor
continue mutable static_cast xor_eq

什么是 C++ 标识符?

用于标识变量、函数、类、模块或其他用户定义项的任何名称都称为 C++ 标识符。标识符的第一个字符是 A 到 Z、a 到 Z 的字母或下划线 (_)。然后添加一个或多个字母、下划线或数字(0 到 9)。

C++ 标识符中不允许使用标点符号 @、$ 和百分号。C++ 也被称为一种大小写敏感的编程语言。因此,在 C++ 中,Manpower 和 manpower 是两个独立的标识符。

可接受标识符的示例


ahmd ayan xyz move_name a_789