先看两个概念(摘自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):
|
|
|
|
|
|
上边一个表格是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