Skip to content
FollowtheDamnCode

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

KeywordWhat it doesExample
charone byte; holds a character or a small integerchar grade = 'A';
intthe everyday whole number (usually 32 bits)int count = 0;
shorta smaller int (usually 16 bits)short s = 300;
longa bigger int (at least 32 bits; long long at least 64)long long big = 9000000000LL;
floata decimal, about 7 digits of precisionfloat f = 2.5f;
doublea decimal, about 15 digits — the default choicedouble pi = 3.14159;
signedcan hold negative values (the default for int)signed char c = -5;
unsignedno negatives; doubles the positive rangeunsigned int u = 4000000000u;
void"nothing": no return value, no parameters, or an untyped pointervoid greet(void);
_Booltrue/false; use it as bool from <stdbool.h>bool done = false;

See Data Types and sizeof.

Building your own types

KeywordWhat it doesExample
structgroups members of different typesstruct Point { int x, y; };
unionmembers share one piece of memoryunion { int i; float f; } u;
enuma set of named integer constantsenum Dir { UP, DOWN };
typedefa new name for an existing typetypedef struct Point Point;

See Structures, Unions, Enums, typedef.

Control flow

KeywordWhat it doesExample
if / elserun code only when a condition is trueif (x > 0) … else …
switch / case / defaultjump to the branch matching a valueswitch (op) { case '+': … }
whilerepeat while a condition is truewhile (n > 0) n--;
dorepeat, checking the condition after each passdo { … } while (again);
fora loop with start, condition, and stepfor (int i = 0; i < n; i++)
breakleave the loop or switch nowif (found) break;
continueskip to the loop's next passif (x < 0) continue;
returnleave the function, optionally with a valuereturn total;
gotojump to a label in the same function — rarely a good ideagoto cleanup;

Storage and qualifiers

KeywordWhat it doesExample
constread-onlyconst int MAX = 10;
staticlocal: keeps its value between calls · global: private to its filestatic int calls = 0;
externdeclares something defined in another fileextern int counter;
auto"an ordinary local" — the default, so never written in Cauto int x;
registerold hint to keep a variable in a CPU registerregister int i;
volatilethe value may change behind the compiler's back (hardware, signals)volatile int flag;
inlinea hint to paste a small function's body at each callinline int sq(int x) { return x * x; }
restrictpromise that a pointer is the only way to reach its datavoid *memcpy(void *restrict d, …)

See Scope and Storage Classes and Const Correctness.

Operator keyword

KeywordWhat it doesExample
sizeofthe size of a type or variable, in bytessizeof(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?