Keywords are predefined (reserved) words in C that have special meaning to the compiler.
- They are part of the language syntax
- They cannot be used as identifiers (variable, function, or struct names)
List of Keywords in C
auto | break | case | char | const | continue | default | do |
double | else | enum | extern | float | for | goto | if |
int | long | register | return | short | signed | sizeof | static |
struct | switch | typedef | union | unsigned | void | volatile | while |
We cannot use these keywords as identifiers (such as variable names, function names, or struct names). The compiler will throw an error if we try to do so.
Example: The code below demonstrates what happens when we use a keyword as a variable name:
#include <stdio.h>
int main() {
int return = 10;
printf("%d\n", return);
return 0;
}
Output
error: expected identifier before 'return'
Let's categorize all keywords based on context for a more clear understanding.
| Category | Keywords |
|---|---|
Data Type Keywords | char, int, float, double, void, short, long, signed, unsigned |
| Operator & Utility Keywords | |
Control Flow Keywords | if, else, switch, case, default, for, while, do, break, continue |
| Storage Class Keywords | auto, register, static, extern |
| Type Qualifiers | const, volatile |
| User Defined Types | struct, union, enum |
Read about Differences between Keywords and Identifiers in C.