C Reference ยท Keywords and Statements
C reserved words (keywords)
The complete list of C keywords through C23, grouped by purpose, with the old underscore spellings, the rules for reserved identifiers and what you cannot name things.
A keyword is a word with a fixed meaning in the C language. You cannot use it as the name of a variable, function, struct tag or macro. C has about 50 keywords, and the list has grown slowly: C99 and C11 added words starting with an underscore and a capital letter, such as _Bool and _Static_assert, so that old programs that used names like bool would keep compiling. C23 promoted many of them to plain keywords.
Beyond keywords, the standard also reserves whole families of identifiers for the implementation. Knowing both rules keeps your names from clashing with the compiler and the library.
int class = 3; /* fine in C, a keyword in C++ */ int register = 1; /* error: register is a keyword */
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.
The keywords
Keywords are case sensitive and always lowercase, except for the older underscore forms.
| Group | Keywords |
|---|---|
| Types | char short int long float double signed unsigned void bool _Complex _Imaginary _BitInt _Decimal32 _Decimal64 _Decimal128 |
| Type declarations | struct union enum typedef |
| Qualifiers | const volatile restrict _Atomic |
| Storage and linkage | auto register static extern thread_local inline |
| Control flow | if else switch case default for while do break continue goto return |
| Operators | sizeof alignof typeof typeof_unqual _Generic |
| Declarations | alignas constexpr static_assert _Noreturn |
| Constants | true false nullptr |
Old and new spellings
| C23 keyword | Older spelling | Notes |
|---|---|---|
bool, true, false |
_Bool, macros in <stdbool.h> |
<stdbool.h> still works and does nothing now. |
alignas, alignof |
_Alignas, _Alignof |
Macros in <stdalign.h> before C23. |
static_assert |
_Static_assert |
The message is optional in C23. |
thread_local |
_Thread_local |
Macro in <threads.h> before C23. |
constexpr, nullptr, typeof |
none | Brand new in C23 (typeof was a GNU extension). |
[[noreturn]] |
_Noreturn |
_Noreturn is obsolescent; see Attributes. |
The old spellings remain valid, so portable code can still use them.
Reserved identifiers
Besides keywords, these names belong to the implementation:
- Any identifier starting with two underscores, or an underscore followed by an uppercase letter (
__x,_Foo), in every scope. - Any identifier starting with a single underscore at file scope (global variables and functions, and
typedefnames). - Every name declared in a standard header you include, and the standard names for macros (
NULL,EOF,INT_MAX). - Names starting with
str,mem,is,tofollowed by a lowercase letter,Efollowed by a digit or uppercase letter,SIG,FE_and others, which the standard may use for future library additions.
Defining your own macro with a keyword's name, as in #define int long, is undefined behavior if any standard header is included afterwards.
Usage notes
- Predefined, not keywords:
main,printf,NULL,EOF,size_tandFILEare ordinary identifiers. You can shadow them, but you should not. - C and C++ differ.
class,new,delete,this,template,namespaceandtryare legal C identifiers but break the program when compiled as C++. Avoid them in headers meant for both languages. boolbefore C23: with-std=c17or earlier,boolneeds#include <stdbool.h>.- Compilers add extensions such as
__attribute__,asm,__typeof__and__int128. In strict modes such as-std=c17, GCC does not recognize plainasm; use__asm__there. - Check the mode.
__STDC_VERSION__is202311Lfor C23,201710Lfor C17 and201112Lfor C11. - Style: pick names that are descriptive and avoid leading underscores entirely.
Related
- Predefined macros,
bool,typeof,nullptr,constexpr, C standards - Lessons: Keywords and identifiers, Modern C