Switching on Strings

Which Are the 32 Keywords in C?

C has 32 keywords in the original standard, from auto and break to while. Here's the full list, grouped by purpose, and why you can't use them as names.

On this page
  1. The 32 keywords at a glance
  2. Types
  3. Storage and qualifiers
  4. Control flow
  5. Other keywords
  6. Keywords cannot be used as names
  7. Keywords added after the original standard
  8. Summary

The 32 keywords at a glance

The original C standard, published in 1989 and often called C89 or ANSI C, defines 32 keywords. A keyword is a reserved word with a fixed meaning, so you cannot use it as the name of a variable, a function or any other identifier. Here is the full list, grouped by purpose:

Group Keywords
Types char, double, float, int, long, short, signed, unsigned, void
Storage and qualifiers auto, const, extern, register, static, typedef, volatile
Control flow break, case, continue, default, do, else, for, goto, if, return, switch, while
Other enum, sizeof, struct, union

That is 9 + 7 + 12 + 4 = 32 keywords. The sections below say briefly what each group is for.

Types

  • int, char, short and long are integer types. The standard sets minimum ranges for them, not exact sizes.
  • signed and unsigned control whether an integer type can hold negative values.
  • float and double are floating-point types.
  • void means no type or no value. It is used for functions that return nothing, and for generic pointers.

Storage and qualifiers

  • auto marks a local variable with automatic storage. Most programmers never write it, because local variables already have that storage by default.
  • static keeps a variable alive for the whole run of the program, or limits a name to the file where it is declared.
  • extern declares a name that is defined somewhere else.
  • register is a hint to the compiler, which can ignore it.
  • const means the value cannot be changed through this name.
  • volatile tells the compiler that a value can change outside the program’s control, so reads should not be optimized away.
  • typedef gives a new name to an existing type.

Control flow

  • if, else, switch, case and default choose which code runs. The switch case statement in C is the usual tool for several fixed options.
  • for, while and do repeat code in loops.
  • break leaves the nearest loop or switch that contains it. Inside a switch, it ends the current case, which is the break statement in C that keeps each case separate.
  • continue skips to the next iteration of a loop.
  • goto jumps to a labeled statement. It is rarely needed in modern code, so use it with care. Learning how to use goto in C also means learning its limits.
  • return ends a function and sends back a value, if the function has a return type.

Other keywords

  • enum defines a set of named integer constants.
  • sizeof is an operator that gives the size of a type or value in bytes. It is a keyword, but it works like an operator, not a function.
  • struct groups several values under one type.
  • union groups values that share the same memory, so only one member holds a meaningful value at a time.

Keywords cannot be used as names

Because keywords are reserved, a declaration such as int return = 5; does not compile. Words that look like ordinary names can also be keywords, so check the list before you pick a name for a variable or function.

Some names are legal in C but reserved in C++. For example, this is valid C because class is not a C keyword:

int class = 3;  /* valid in C, not in C++ */

C++ has a longer keyword list that includes class, new, delete, template, namespace and bool. Code that compiles as C may therefore fail when you compile it as C++.

Keywords added after the original standard

Later C standards added more reserved words. C99 added words such as inline, restrict and _Bool. C11 added words such as _Generic and _Static_assert. In C99 through C17, the bool, true and false names come from the <stdbool.h> header as macros, not keywords. C23 made bool, true and false keywords, so newer code may not need that header.

So the count of 32 applies to the original standard. If you compile with a newer C standard, the reserved list is longer, and you should check the standard your compiler is set to use.

Summary

The original C standard has 32 keywords. They cover types, storage and qualifiers, control flow and a few other words, and none of them can be used as a name. Later standards add more, and C++ reserves a longer list still.

The complete guide to switching on strings

How to Switch on a String in C++
Read the guide

Keep exploring

Guides from other topics

All topics →