Keywords in C
Keywords in C are predefined, reserved words that have a specific meaning in the language. They cannot be used as identifiers such as variable names, function names, or labels. Keywords form the foundation of the C programming language and define the structure and behavior of programs.
Complete List of 32 Keywords
The following table lists all the standard keywords used in C programming, categorized by their functionality:
There are 32 standard keywords in C (as per C89/C90 standard) and each keyword has a specific purpose, such as defining data types, controlling program flow, or managing memory.
| Category | Keywords | Purpose |
|---|---|---|
| Data Types | int, float, char, double, void | Defines the type of data a variable can hold. |
| Flow Control | if, else, switch, case, default | Used for decision-making and branching. |
| Loop Control | for, while, do, break, continue | Used to repeat a block of code or exit loops. |
| Storage Classes | auto, extern, register, static | Defines the scope and lifetime of variables. |
| User-Defined Types | struct, union, enum, typedef | Used to create complex custom data structures. |
| Type Qualifiers | const, volatile | Adds special properties to variables (e.g., read-only). |
| Function Related | return | Exits a function and optionally returns a value. |
| Memory & Sizes | sizeof | Calculates the size of data types or variables. |
| Other Reserved | goto, signed, unsigned, long, short | Various modifiers and jump statements. |
What Are Keywords?
Keywords are reserved words that the compiler recognizes as part of the language syntax. Since they have predefined meanings, programmers cannot redefine them for other purposes.
Examples of keywords include int, float, char, if, else, while, for, return, break, and continue.
Purpose of Keywords
Keywords provide the basic instructions for writing C programs. They are used for declaring variables, controlling program flow, defining functions, managing memory, and implementing logic.
Without keywords, the compiler would not understand the intended operations or the structure of the program.
List of Common Keywords in C
Here is a list of some frequently used C keywords along with their purpose:
1. int – declares integer variables 2. float – declares floating-point variables 3. char – declares character variables 4. double – declares double precision variables 5. void – indicates no value returned from a function 6. if – starts a conditional statement 7. else – defines an alternative block in a conditional statement 8. for – defines a loop with a known number of iterations 9. while – defines a loop with an unknown number of iterations 10. do – defines a loop that executes at least once 11. switch – starts a multiple-selection statement 12. case – defines a case in a switch statement 13. break – exits loops or switch statements 14. continue – skips the current loop iteration and continues 15. return – returns a value from a function
Important Points About Keywords
1. Keywords are **case-sensitive**. For example, 'int' is valid, but 'Int' or 'INT' is not. 2. Keywords cannot be used as variable names, function names, or identifiers. 3. Using a keyword incorrectly will result in a compilation error. 4. Keywords form the syntax and structure of all C programs, making them essential to learn.
Example Using Keywords in C
Here is a simple example demonstrating the use of keywords in C:
```c
#include
Explanation: - `int` and `float` are data type keywords. - `if` and `else` control the program flow. - `return` ends the function and returns a value. - `main` function is required as the entry point for the program.
Conclusion
Keywords are the backbone of the C programming language. Understanding and using them correctly is essential for writing syntactically correct, readable, and maintainable code.
Beginners should memorize common keywords and understand their purpose, as they are used in almost every C program.
Codecrown