C、C++、C#、Java、Python保留字分类整理

本文概述了C、C++、C#、Java和Python等编程语言的关键字列表,包括它们各自的保留字数量、新增关键字以及各自的特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C语言保留字

在ANSI C标准中,C语言共有32个关键字,包含9种控制语句,区分大小写;C99在其基础上,新增5个关键字;C11又新增7个关键字,总共44个。

32
数值类型7short, int, long,
double, float,
unsigned, signed,
其他类型1char
类型判定2typedef, sizeof
声明结构3struct, enum, union,
特征修饰2const, volatile
存储器指定4auto, register, static, extern
条件语句5if, else, switch, case, default
循环语句5for, do, while, continue, break
函数相关2void,return
无条件跳转1goto

部分说明:

  • 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个。

73C++保留字
数值类型7int, long, short, double, float, unsigned, signed
字符类型4char, wchar_t, char16_t, char32_t
枚举;布尔4enum, bool, false, true,
类型转换4const_cast,dynamic_cast,
static_cast,reinterpret_cast
类型修饰4const, volatile, mutable ,constexpr
类与对象6class, struct, union ,delete ,new ,this
类成员限制3private ,protected ,public
函数相关6void, return, explicit, friend, inline,virtual
存储器指定4static, extern, decltype, thread_local
条件语句5if, else, switch, case, default
循环语句5for, do, while, continue, break
类型相关4typedef, sizeof, typeid, typename
对齐2alignas, alignof
调试5catch, throw, try, static_assert, noexcept
未分类4operator, template, nullptr, asm,using, namespace
乏用或废除4auto, export, register, goto,

说明:

  1. 粗体不存在于C语言中;
  2. 未分类关键字中,operator用于运算符重载;template用于声明模板;nummptr声明空指针
  3. auto在C++98/03中,表示自动储存类型;在C++11中,表示由编译器静态判断其应有的类型,当无其他声明时为默认声明,可写可不写。
  4. export已废除,但仍是保留字;register已被好多编译器无视,可能在将来废除
  5. C++11新增保留字如下表
C++11新增
alignasalignofchar16_tchar32_tconstexpr
decltypenoexceptnullptrstatic_assertthread_local

C#保留字

77C#保留字
整型8byte, sbyte, short, ushort, int, uint, long, ulong,
其他类型6float, double, decimal, char, bool, enum
常量3false, true, null
引用类型3object, string, delegate,
类型相关6as, is, typeof, sizeof, const, volatile
方法参数4in, out, ref, params
类声明4class, struct, abstract, interface,
类修饰6extern, static, sealed, virtual, unsafe, readonly
成员修饰6event, internal, private, protected, public, override
类访问2base, this,
显隐式转换3operator, implicit, explicit
函数相关3void, return, new
条件语句5switch, case, default, if, else
循环语句6do, while, for, break, continue, foreach
调试6try, catch, throw, finally, checked, unchecked
内存3fixed, lock, stackalloc
其他3goto, using, namespace

说明:

  1. in可用于foeach in语句
  2. 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
权限修饰符3private, protected, public
类型修饰符4abstract, final, static, synchronized
类间关系2extends, implements
实例4new, this, super, instanceof
调试5try, catch, finally, throw, throws
包相关2package, import
常量3TRUE, FALSE, null
其他5native, strictfp, transient, volatile, assert
未使用2goto, const

python

由于不需要声明变量以及内置结构的类型,所以保留字十分精简,只有35个,可通过如下命令查看

>>> import keyword
>>> len(keyword.kwlist)     #返回35
35Python保留字
常量3True, False, None
逻辑4is, not, or, and
声明5def, class, lambda, global, nonlocal
流程3
5
5
if, elif, else,
for, in, while, continue, break,
pass, return, yield, with, as
异常5try, expect, raise, finally, assert
其他5import, from, del, async, await
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微小冷

请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值