C语言保留字
在ANSI C标准中,C语言共有32个关键字,包含9种控制语句,区分大小写;C99在其基础上,新增5个关键字;C11又新增7个关键字,总共44个。
32 | ||
---|---|---|
数值类型 | 7 | short , int , long ,double , float ,unsigned , signed , |
其他类型 | 1 | char |
类型判定 | 2 | typedef , sizeof |
声明结构 | 3 | struct , enum , union , |
特征修饰 | 2 | const , volatile |
存储器指定 | 4 | auto , register , static , extern |
条件语句 | 5 | if , else , switch , case , default |
循环语句 | 5 | for , do , while , continue , break |
函数相关 | 2 | void ,return |
无条件跳转 | 1 | goto |
部分说明:
volatile
:用于防止编译器优化
C99新增 | 5个 |
---|---|
inline | 用于指定内联函数,可取代宏 |
restrict | 用于保护被指针引用的对象 |
-Bool | 布尔数据类型 |
_Complex | 复数数据类型,用I 表示虚数 |
_Imaginary | 虚数类型 |
C11新增 | 7个 |
---|---|
_Alignas | 按照指定数据类型对齐 |
_Alignof | 返回数据类型内存对齐的字节数 |
_Atomic | 被修饰变量工作时,禁止其他线程调用 |
_Static_assert | 静态断言 |
_Noreturn | 调用完成后,不反悔到主调函数 |
_Thread_local | 声明线程存储器 |
_Generic |
Cpp保留字
ISO C++98/03关键字共63个,C++11新增10个。
73 | C++保留字 | |
---|---|---|
数值类型 | 7 | int , long , short , double , float , unsigned , signed |
字符类型 | 4 | char , wchar_t , char16_t , char32_t |
枚举;布尔 | 4 | enum , bool , false , true , |
类型转换 | 4 | const_cast ,dynamic_cast ,static_cast ,reinterpret_cast |
类型修饰 | 4 | const , volatile , mutable ,constexpr |
类与对象 | 6 | class , struct , union ,delete ,new ,this |
类成员限制 | 3 | private ,protected ,public |
函数相关 | 6 | void , return , explicit , friend , inline ,virtual |
存储器指定 | 4 | static , extern , decltype , thread_local |
条件语句 | 5 | if , else , switch , case , default |
循环语句 | 5 | for , do , while , continue , break |
类型相关 | 4 | typedef , sizeof , typeid , typename |
对齐 | 2 | alignas , alignof |
调试 | 5 | catch , throw , try , static_assert , noexcept |
未分类 | 4 | operator , template , nullptr , asm ,using , namespace |
乏用或废除 | 4 | auto , export , register , goto , |
说明:
- 粗体不存在于C语言中;
- 未分类关键字中,
operator
用于运算符重载;template
用于声明模板;nummptr
声明空指针 auto
在C++98/03中,表示自动储存类型;在C++11中,表示由编译器静态判断其应有的类型,当无其他声明时为默认声明,可写可不写。export
已废除,但仍是保留字;register
已被好多编译器无视,可能在将来废除- C++11新增保留字如下表
C++11 | 新增 | |||
---|---|---|---|---|
alignas | alignof | char16_t | char32_t | constexpr |
decltype | noexcept | nullptr | static_assert | thread_local |
C#保留字
77 | C#保留字 | |
---|---|---|
整型 | 8 | byte, sbyte, short, ushort, int, uint, long, ulong, |
其他类型 | 6 | float, double, decimal, char, bool, enum |
常量 | 3 | false, true, null |
引用类型 | 3 | object, string, delegate, |
类型相关 | 6 | as, is, typeof, sizeof, const, volatile |
方法参数 | 4 | in, out, ref, params |
类声明 | 4 | class, struct, abstract, interface, |
类修饰 | 6 | extern, static, sealed, virtual, unsafe, readonly |
成员修饰 | 6 | event, internal, private, protected, public, override |
类访问 | 2 | base, this, |
显隐式转换 | 3 | operator, implicit, explicit |
函数相关 | 3 | void, return, new |
条件语句 | 5 | switch, case, default, if, else |
循环语句 | 6 | do, while, for, break, continue, foreach |
调试 | 6 | try, catch, throw, finally, checked, unchecked |
内存 | 3 | fixed, lock, stackalloc |
其他 | 3 | goto, using, namespace |
说明:
in
可用于foeach in
语句operator
可用于运算符重载
Java保留字
51 | ||
---|---|---|
数据类型 | 6 6 | class, interface, enum, char, boolean, void byte, short, int, long, float, double |
流程控制 | 5 6 | if, else, switch, case, default while, do, for, break, continue, return |
权限修饰符 | 3 | private, protected, public |
类型修饰符 | 4 | abstract, final, static, synchronized |
类间关系 | 2 | extends, implements |
实例 | 4 | new, this, super, instanceof |
调试 | 5 | try, catch, finally, throw, throws |
包相关 | 2 | package, import |
常量 | 3 | TRUE, FALSE, null |
其他 | 5 | native, strictfp, transient, volatile, assert |
未使用 | 2 | goto, const |
python
由于不需要声明变量以及内置结构的类型,所以保留字十分精简,只有35个,可通过如下命令查看
>>> import keyword
>>> len(keyword.kwlist) #返回35
35 | Python保留字 | |
---|---|---|
常量 | 3 | True, False, None |
逻辑 | 4 | is, not, or, and |
声明 | 5 | def, class, lambda, global, nonlocal |
流程 | 3 5 5 | if, elif, else, for, in, while, continue, break, pass, return, yield, with, as |
异常 | 5 | try, expect, raise, finally, assert |
其他 | 5 | import, from, del, async, await |