【C/C++关键字】 C/C++关键字总结

先看两个概念(摘自wiki):

关键字 ( keyword):word or identifier that has a particular meaning to the programming language;

保留字 ( reserved word):a reserved word is a word that cannot be used as an identifier, and a reserved word may have no meaning.

关键字是对编程语言有特定含义的词或标识符,保留字是不能定义为标识符的词,为系统保留,有些保留字可能并没有什么意义。例如java中的goto保留字,它并不是关键字,没有什么具体含义,仅为系统保留而已。

说了那么多,其实,,c和c++是不区分保留字和关键字的,c和c++所有的保留字都是关键字。

c/c++关键字(摘自cppreference.com):

auto
break
case
char
const
continue
default
do
double
else
enum
extern

float
for
goto
if
inline (since C99)
int
long
register
restrict (since C99)
return
short

signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while

_Alignas (since C11)
_Alignof (since C11)
_Atomic (since C11)
_Bool (since C99)
_Complex (since C99)
_Generic (since C11)
_Imaginary (since C99)
_Noreturn (since C11)
_Static_assert (since C11)
_Thread_local (since C11)

alignas (since C++11)
alignof (since C++11)
and
and_eq
asm
atomic_cancel (TM TS)
atomic_commit (TM TS)
atomic_noexcept (TM TS)
auto(1)
bitand
bitor
bool
break
case
catch
char
char16_t (since C++11)
char32_t (since C++11)
class(1)
compl
concept (since C++20)
const
constexpr (since C++11)
const_cast
continue
co_await (coroutines TS)
co_return (coroutines TS)
co_yield (coroutines TS)
decltype (since C++11)
default(1)
delete(1)

do
double
dynamic_cast
else
enum
explicit
export(1)
extern(1)
false
float
for
friend
goto
if
import (modules TS)
inline(1)
int
long
module (modules TS)
mutable(1)
namespace
new
noexcept (since C++11)
not
not_eq
nullptr (since C++11)
operator
or
or_eq
private
protected
public

register(2)
reinterpret_cast
requires (since C++20)
return
short
signed
sizeof(1)
static
static_assert (since C++11)
static_cast
struct(1)
switch
synchronized (TM TS)
template
this
thread_local (since C++11)
throw
true
try
typedef
typeid
typename
union
unsigned
using(1)
virtual
void
volatile
wchar_t
while
xor
xor_eq

上边一个表格是c关键字,下面一个表格为c++关键字

  • (1) - meaning changed or new meaning added in C++11. Note: the keyword export is also used by Modules TS.
  • (2) - meaning changed in C++17.


c++关键字分类:

数据类型:void,int,char,float,double,bool,w_char
类型定义:struct,union,enum,class,typedef
常量值:true,false
类型修饰符:long,short,singed,unsigned
类型限定符:const,volatile,restrict
存储说明符:auto,register,static,extern,thread_local,mutable
其它修饰符:inline,asm
循环控制:for,while,do
跳转控制:break,continue,return,goto
分支结构: if,else,switch,case,default
内存管理:new, delete
运算符:sizeof,and,and_eq,bitand,bitor,compl,not,not_eq,or,or_eq,xor,xor_eq
访问限定符:this,friend,virtual,mutable,explicit,operator
类访问修饰符:private,protected,public
模板:template,typename
命名空间:namespace,using
异常处理:throw,try,catch

猜你喜欢

转载自blog.csdn.net/zhanw15/article/details/80502049
今日推荐