C keywords are predefined, reserved words that have special meanings in the C programming language. These words form the foundation of C's syntax and cannot be used as identifiers for variables, functions, or other user-defined elements.
Keywords in C serve specific purposes and are integral to the language's structure. They define control flow, data types, and other fundamental aspects of C programming. Recognizing and using these keywords correctly is crucial for writing valid and efficient C code.
C has a set of 32 keywords (C89/C90 standard) or 37 keywords (C99 standard). Here's a table of commonly used C keywords:
| Keyword | Purpose |
|---|---|
| int | Integer data type |
| float | Floating-point data type |
| char | Character data type |
| if | Conditional statement |
| else | Alternative for conditional statement |
| for | Loop construct |
| while | Loop construct |
| return | Function return statement |
C keywords are essential for defining program structure, declaring variables, and controlling program flow. Let's look at some examples of how keywords are used in C programs.
#include <stdio.h>
int main() {
int age = 18;
if (age >= 18) {
printf("You are eligible to vote.\n");
} else {
printf("You are not eligible to vote yet.\n");
}
return 0;
}
In this example, we use the keywords int, if, else, and return. These keywords help define the variable type, create a conditional statement, and specify the function's return value.
#include <stdio.h>
int main() {
for (int i = 0; i < 5; i++) {
printf("Iteration %d\n", i);
}
return 0;
}
This example demonstrates the use of the for keyword to create a loop. The int keyword is used within the loop initialization.
int is a keyword, but Int or INT are not._Bool in C99).C keywords are the backbone of the C programming language. They provide the structure and functionality necessary for creating robust and efficient programs. By understanding and correctly using C keywords, you'll be well on your way to becoming a proficient C programmer.
To further enhance your C programming skills, explore related topics such as C Data Types, C Operators, and C Control Structures.