18-关键字和保留标识符
2.8 关键字和保留标识符
关键字是C语言的词汇。它们对C而言比较特殊,不能用它们作为标识符(如,变量名)。许多关键字用于指定不同的类型,如 int
。还有一些关键字(如, if
)用于控制程序中语句的执行顺序。在表 2.2
中所列的C语言关键字中,粗体表示的是 C90
标准新增的关键字,斜体表示的 C99
标准新增的关键字,粗斜体表示的是 C11
标准新增的关键字。
| auto
| extern
| short
| while
|
| :----- | :----- | :----- | :----- | :----- | :----- |
| break
| float
| signed
| _Alignas
|
| case
| for
| sizeof
| _Alignof
|
| char
| goto
| static
| _Atomic
|
| const
| if
| struct
| _Bool
|
| continue
| inline
| switch
| _Complex
|
| default
| int
| typedef
| _Generic
|
| do
| long
| union
| _Imaginary
|
| double
| register
| unsigned
| _Noreturn
|
| else
| restrict
| void
| _Static_assert
|
| enum
| return
| volatile
| _Thread_local
|
如果使用关键字不当(如,用关键字作为变量名),编译器会将其视为语法错误。还有一些保留标识符(reserved identifier
),C语言已经指定了它们的用途或保留它们的使用权,如果你使用这些标识符来表示其他意思会导致一些问题。因此,尽管它们也是有效的名称,不会引起语法错误,也不能随便使用。保留标识符包括那些以下划线字符开头的标识符和标准库函数名,如 printf()
。