Keywords in C
Keywords are reserved words in C which have a special meaning for the compiler. These words are already defined by the C language, so we cannot use them as variable names, function names or other identifiers.
Keywords form the basic structure and syntax of a C program. In standard C, there are 32 keywords.
Rules for Keywords
Important Rules:
- Keywords cannot be used as identifiers.
- Keywords are case-sensitive in C.
- All C keywords are written in lowercase letters.
- Using a keyword as a variable name gives a compilation error.
All 32 Keywords in C
| Keywords | Keywords | Keywords | Keywords |
|---|---|---|---|
| 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 |
Example:
#include <stdio.h>
int main() {
int age = 18;
if (age >= 18) {
printf("Eligible");
}
return 0;
}
Output:
Eligible
Explanation:
intis a keyword used to declare integer data type.ifis a keyword used for decision making in C.returnis a keyword used to return control from the function.main,ageandprintfare identifiers, not keywords.- The condition
age >= 18checks whether the person's age is 18 or more. - Since the condition is true,
printf()prints "Eligible" on the screen.
Valid vs Invalid Usage
// Valid
int number = 10;
// Invalid
int return = 5; // return is a keyword
Output:
Compilation error
Explanation:
- number is valid because it is not a keyword.
- return is a reserved keyword, so using it as a variable name gives a compilation error.
Real-Life Analogy:
Just like traffic signs on the road have fixed meanings (we cannot change their meaning), keywords in C also have fixed meanings and cannot be used for anything else.
Summary:
- Keywords are reserved words with fixed meaning.
- C has 32 standard keywords.
- Keywords are predefined by the C language.
- They cannot be used as identifiers (variable names or function names).
- Examples: int, float, if, return, while.