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.

CategoryKeywordsPurpose
Data Typesint, float, char, double, voidDefines the type of data a variable can hold.
Flow Controlif, else, switch, case, defaultUsed for decision-making and branching.
Loop Controlfor, while, do, break, continueUsed to repeat a block of code or exit loops.
Storage Classesauto, extern, register, staticDefines the scope and lifetime of variables.
User-Defined Typesstruct, union, enum, typedefUsed to create complex custom data structures.
Type Qualifiersconst, volatileAdds special properties to variables (e.g., read-only).
Function RelatedreturnExits a function and optionally returns a value.
Memory & SizessizeofCalculates the size of data types or variables.
Other Reservedgoto, signed, unsigned, long, shortVarious 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 int main() { int a = 10; float b = 5.5; if (a > b) { printf("a is greater than b\n"); } else { printf("b is greater than or equal to a\n"); } return 0; } ```

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.