C++ 关键字
1.5 关键字
作用:关键字是C++中预先保留的单词(标识符)
- 在定义变量或者常量时候,不要用关键字
C++关键字如下
| asm | do | if | return | typedef |
|---|---|---|---|---|
| auto | double | inline | short | typeid |
| bool | dynamic_cast | int | signed | typename |
| break | else | long | sizeof | union |
| case | enum | mutable | static | unsigned |
| catch | explicit | namespace | static_cast | using |
| char | export | new | struct | virtual |
| class | extern | operator | switch | void |
| const | false | private | template | volatile |
| const_cast | float | protected | this | wchar_t |
提升:在给变量或者常量起名称时候,不要用C++得关键字,否则会产生歧义。
示例:
#include <iostream>
using namespace std;
int main() {
// 创建变量:数据类型 变量名称 = 变量初始值
// 不要用关键字给变量或者常量起名称
// int int = 10; // 错误,第二个int是关键字,不可以作为变量得名称
system("pause");
return 0;
}

浙公网安备 33010602011771号