Reference: Keywords
Every C keyword, grouped by what it's for.
4 minute read
Big idea
C has a small vocabulary. These keywords are reserved: you can't use them as names for variables or functions. This page lists each one, what it's for, and where it's taught.
Types
| Keyword | What it does | Example |
|---|---|---|
char | one byte; holds a character or a small integer | char grade = 'A'; |
int | the everyday whole number (usually 32 bits) | int count = 0; |
short | a smaller int (usually 16 bits) | short s = 300; |
long | a bigger int (at least 32 bits; long long at least 64) | long long big = 9000000000LL; |
float | a decimal, about 7 digits of precision | float f = 2.5f; |
double | a decimal, about 15 digits — the default choice | double pi = 3.14159; |
signed | can hold negative values (the default for int) | signed char c = -5; |
unsigned | no negatives; doubles the positive range | unsigned int u = 4000000000u; |
void | "nothing": no return value, no parameters, or an untyped pointer | void greet(void); |
_Bool | true/false; use it as bool from <stdbool.h> | bool done = false; |
See Data Types and sizeof.
Building your own types
| Keyword | What it does | Example |
|---|---|---|
struct | groups members of different types | struct Point { int x, y; }; |
union | members share one piece of memory | union { int i; float f; } u; |
enum | a set of named integer constants | enum Dir { UP, DOWN }; |
typedef | a new name for an existing type | typedef struct Point Point; |
See Structures, Unions, Enums, typedef.
Control flow
| Keyword | What it does | Example |
|---|---|---|
if / else | run code only when a condition is true | if (x > 0) … else … |
switch / case / default | jump to the branch matching a value | switch (op) { case '+': … } |
while | repeat while a condition is true | while (n > 0) n--; |
do | repeat, checking the condition after each pass | do { … } while (again); |
for | a loop with start, condition, and step | for (int i = 0; i < n; i++) |
break | leave the loop or switch now | if (found) break; |
continue | skip to the loop's next pass | if (x < 0) continue; |
return | leave the function, optionally with a value | return total; |
goto | jump to a label in the same function — rarely a good idea | goto cleanup; |
Storage and qualifiers
| Keyword | What it does | Example |
|---|---|---|
const | read-only | const int MAX = 10; |
static | local: keeps its value between calls · global: private to its file | static int calls = 0; |
extern | declares something defined in another file | extern int counter; |
auto | "an ordinary local" — the default, so never written in C | auto int x; |
register | old hint to keep a variable in a CPU register | register int i; |
volatile | the value may change behind the compiler's back (hardware, signals) | volatile int flag; |
inline | a hint to paste a small function's body at each call | inline int sq(int x) { return x * x; } |
restrict | promise that a pointer is the only way to reach its data | void *memcpy(void *restrict d, …) |
See Scope and Storage Classes and Const Correctness.
Operator keyword
| Keyword | What it does | Example |
|---|---|---|
sizeof | the size of a type or variable, in bytes | sizeof(int), sizeof arr |
Newer additions
C11 and later added keywords starting with an underscore and a capital — _Alignas, _Alignof, _Atomic, _Generic, _Noreturn, _Static_assert, _Thread_local, _Complex, _Imaginary. You'll rarely need them while learning. C23 also makes bool, true, false, nullptr, constexpr, and typeof keywords.
Not keywords (but just as reserved in practice)
main, printf, NULL, true, false (before C23), and bool (before C23) are not keywords — they're names from the library or headers. You could reuse some of them, but don't.
Which of these can't be used as a variable name?
Key terms
- Keyword — A word reserved by the language for its own meaning.
- Identifier — A name you choose: letters, digits, and
_, not starting with a digit, not a keyword. - Qualifier — A keyword that adjusts a type:
const,volatile,restrict.
Check yourself
Which of these is NOT a C keyword?
Which keyword makes a global private to its file?