Keywords are reserved words in C that have special meanings defined by the language. They are part of the C syntax and cannot be used as identifiers (variable names, function names, etc.). Here’s a detailed explanation of keywords in C:

What Are Keywords?

Keywords are reserved words predefined by the C compiler that convey specific instructions. Since they are part of the language syntax, they must be used according to their intended functionality, and you cannot use them as names for variables or functions.

List of C Keywords

Below is a list of common keywords in the C language and their functions:

  1. auto: Used for automatic variable declarations (default behavior, rarely used explicitly).
  2. break: Terminates the current loop or switch statement.
  3. case: Defines a branch in a switch statement.
  4. char: Declares a character data type.
  5. const: Defines constant values that cannot be modified.
  6. continue: Skips the current iteration of a loop and moves to the next iteration.
  7. default: Specifies the default block of code in a switch statement if no case matches.
  8. do: Starts a do-while loop, which executes the loop body at least once.
  9. double: Declares a double-precision floating-point number.
  10. else: Defines the alternative block of code for an if condition.
  11. enum: Declares an enumeration, a user-defined type for named integer constants.
  12. extern: Declares a global variable or function that is defined elsewhere.
  13. float: Declares a floating-point data type.
  14. for: Starts a for loop, commonly used for iteration.
  15. goto: Transfers control to a labeled statement (not recommended, as it makes code harder to read).
  16. if: Used for conditional branching.
  17. int: Declares an integer data type.
  18. long: Declares a long integer, a larger version of int.
  19. register: Suggests storing the variable in a CPU register for fast access (modern compilers usually ignore this).
  20. return: Exits from a function and optionally returns a value.
  21. short: Declares a short integer, which uses less memory than int.
  22. signed: Declares a signed type, which can hold both positive and negative values.
  23. sizeof: Returns the size of a data type or variable in bytes.
  24. static: Defines the lifetime and visibility of a variable or function:
    • When used with variables, retains the value between function calls.
    • When used with functions, restricts visibility to the current file.
  25. struct: Declares a structure, a collection of variables of different data types under a single name.
  26. switch: A multi-way branching statement based on the value of a variable.
  27. typedef: Defines an alias for an existing data type.
  28. union: Declares a union, similar to a struct, but members share the same memory space.
  29. unsigned: Declares an unsigned type that can hold only positive values (or zero).
  30. void: Declares a function that does not return a value or a pointer to "nothing."
  31. volatile: Indicates that a variable’s value may be changed by something beyond the control of the code section in which it appears.
  32. while: Starts a while loop, which continues as long as the given condition is true.

Examples of Commonly Used Keywords

  1. if, else, and return:

    int main() { int a = 5; if (a > 3) { return 1; } else { return 0; } }
  2. for Loop:

    for (int i = 0; i < 10; i++) { printf("%d\n", i); }
  3. switch Statement:

    int day = 3; switch (day) { case 1: printf("Monday"); break; case 2: printf("Tuesday"); break; default: printf("Another day"); }

Summary

  • Keywords are Reserved Words: They cannot be used as variable or function names.
  • Keywords Are Built-in: Each has a specific, well-defined purpose in the language.
  • Understanding Their Use: Familiarizing yourself with C keywords is essential for writing clear and correct C programs.

Mastering C keywords will allow you to control the flow of your program, define data, and perform various operations effectively.