Keywords in C are reserved words that already have special meanings in the language. They are part of the language syntax itself, so the programmer cannot redefine them for personal use. This is why words such as int, if, return, and while cannot be used as ordinary variable names.
This topic looks simple at first, but it is more important than it appears. Keywords are not just a list to memorize for exams. They describe how the C language is built. Once you understand what different keywords do, the overall structure of C becomes easier to read and write. In this article, we will understand what keywords in C are, why they are reserved, how they differ from identifiers, the classic 32 keywords commonly taught to beginners, and how modern C standards add more reserved words.
What are Keywords in C?
Keywords in C are predefined words that have fixed meanings for the compiler. The compiler interprets them according to the rules of the language. Because of this, a keyword cannot be used as the name of a variable, function, array, or any other user-defined identifier.
For example, if you write int total;, the word int tells the compiler that total is an integer variable. If int were allowed to be used freely as a user-defined name, the compiler would not be able to understand the program correctly.
Why are Keywords Reserved in C?
- They define the grammar of the language.
- They tell the compiler how statements and declarations should be interpreted.
- They make program structure consistent across all valid C programs.
- They prevent ambiguity between language commands and programmer-defined names.
If reserved words were not protected, a beginner could accidentally create variables with names such as while or return, which would immediately break the meaning of the program.
Keywords vs Identifiers in C
This distinction is essential. A keyword has a predefined meaning in the language. An identifier is a name created by the programmer.
| Term | Meaning | Example |
|---|---|---|
| Keyword | Reserved word with fixed compiler meaning | int, if, return |
| Identifier | User-defined name for a program element | total, marks, main |
For example, in the declaration int marks;, the word int is a keyword, while marks is an identifier.
The Classic 32 Keywords in C
Many introductory books and courses teach the classic 32 keywords of traditional C. These are still the most useful starting point for beginners. The exact set of reserved words depends on the C standard version and compiler mode, but the classic list below is the one most students see first.
| Keyword | Category | Main Purpose |
|---|---|---|
auto | Storage class | Declares an automatic local variable |
break | Jump/control | Exits a loop or switch statement |
case | Selection | Defines a branch inside switch |
char | Data type | Represents character data |
const | Type qualifier | Marks an object as not modifiable through that name |
continue | Jump/control | Skips to the next loop iteration |
default | Selection | Defines the fallback branch in switch |
do | Loop | Starts a do while loop |
double | Data type | Represents double-precision floating-point values |
else | Selection | Defines the alternate branch of an if statement |
enum | User-defined type | Creates an enumeration type |
extern | Storage class | Refers to a declaration defined elsewhere |
float | Data type | Represents single-precision floating-point values |
for | Loop | Starts a for loop |
goto | Jump/control | Transfers control to a labeled statement |
if | Selection | Starts a conditional branch |
int | Data type | Represents integer values |
long | Type modifier | Modifies integer or floating type size/range |
register | Storage class | Suggests register storage for a variable |
return | Jump/control | Exits a function and optionally returns a value |
short | Type modifier | Requests a shorter integer form |
signed | Type modifier | Indicates signed numeric representation |
sizeof | Operator keyword | Returns the size of a type or object |
static | Storage class | Changes storage duration or linkage behavior |
struct | User-defined type | Defines a structure type |
switch | Selection | Starts multi-way selection logic |
typedef | Type aliasing | Creates a new name for a type |
union | User-defined type | Defines a union type |
unsigned | Type modifier | Indicates unsigned numeric representation |
void | Data type | Represents no value or no type result |
volatile | Type qualifier | Tells the compiler a value may change unexpectedly |
while | Loop | Starts a while loop |
How Keywords in C are Commonly Grouped
Memorizing the full list randomly is harder than learning the keywords by purpose. Grouping them makes the language easier to understand.
1. Data Type Keywords
Keywords such as char, int, float, double, and void represent the basic built-in types of the language.
2. Type Modifiers and Qualifiers
Keywords such as short, long, signed, and unsigned adjust type behavior. Keywords such as const and volatile describe important constraints on how data may be used or changed.
3. Control Flow Keywords
Keywords such as if, else, switch, case, default, for, while, do, break, continue, goto, and return control the direction of program execution.
4. Storage Class Keywords
Keywords such as auto, register, static, and extern affect storage duration, scope, or linkage.
5. User-Defined Type Keywords
Keywords such as struct, union, enum, and typedef are used to build more meaningful data models in real programs.
Examples of Keywords in Real C Code
The following example shows several common keywords working together in a simple program.
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 5; i++)
{
if (i == 3)
{
continue;
}
printf("%d\n", i);
}
return 0;
}In this short example, int, for, if, continue, and return are all keywords. Each one controls how the compiler understands the program.
Here is another example using type-related keywords.
typedef struct
{
int id;
char grade;
} Student;
const int max_students = 60;This example uses typedef, struct, int, char, and const. These are all reserved words with fixed meanings in C.
Can Keywords be Used as Variable Names?
No. A keyword cannot be used as an identifier. For example, declarations such as int return; or float while; are invalid because return and while are already reserved by the language.
This is why beginners must learn the difference between keywords and identifiers early. A valid identifier should follow naming rules and must not match any reserved word.
Are There Only 32 Keywords in C?
Not exactly. The classic 32 keywords are the traditional set commonly taught in introductory material, especially when the focus is on older ANSI C style learning. However, newer C standards added more reserved words.
- C99 introduced keywords such as
inline,restrict, and_Bool. - C99 also added complex-number-related keywords such as
_Complexand_Imaginary. - C11 introduced keywords such as
_Alignas,_Alignof,_Atomic,_Generic,_Noreturn,_Static_assert, and_Thread_local.
So the exact number of reserved words depends on the C standard being used. For beginner learning paths, the classic 32 are still a useful core set, but it is more accurate to say that modern C can have more than 32 keywords.
Most Important Keywords for Beginners
Not every keyword matters equally on day one. If you are just starting C, focus first on the ones that appear constantly in normal code.
int,char,float,doubleif,else,switch,case,defaultfor,while,dobreak,continue,returnconst,static,sizeofstruct,typedef,enum
Once those become familiar, the rest of the keyword list becomes much easier to understand in context.
Common Mistakes Related to Keywords in C
- Trying to use a keyword as a variable name
- Memorizing keywords without understanding what they do
- Confusing keywords with standard library function names
- Assuming the keyword list is identical across all C standards
- Ignoring the difference between older teaching material and modern C revisions
For example, printf is not a keyword. It is a library function declared in stdio.h. This distinction matters because keywords belong to the language itself, while library functions belong to headers and libraries.
FAQs
What are keywords in C?
Keywords in C are reserved words with predefined meanings for the compiler. They are part of the language syntax and cannot be used as ordinary identifiers.
How many keywords are there in C?
Introductory material often teaches the classic 32 keywords of traditional C, but modern C standards include additional reserved words, so the exact number depends on the standard version.
Can a keyword be used as a variable name in C?
No. Keywords are reserved by the language, so they cannot be used as variable names, function names, or other user-defined identifiers.
Is printf a keyword in C?
No. printf is a standard library function, not a language keyword.
What is the difference between keywords and identifiers in C?
A keyword has a fixed compiler-defined meaning, while an identifier is a programmer-defined name used for variables, functions, arrays, structures, and other program elements.