c

C keywords are reserved words that have a special meaning to the compiler and cannot be used as identifiers (variable names, function names, etc.). There are 32 original keywords in the ANSI C (C89) standard, with more added in later versions like C99 and C11.

1. Primary Data Types

These keywords are used to define the type of data a variable can hold:

  • int: Used for integer values.

  • char: Used for character values.

  • float: Used for single-precision floating-point numbers.

  • double: Used for double-precision floating-point numbers.

  • void: Represents the absence of type (used for functions returning nothing or generic pointers).

2. Control Flow and Branching

Keywords used to control the execution logic of the program:

  • if and else: Used for conditional execution.

  • switch, case, and default: Used for multi-way branching.

  • for, while, and do: Used for loop structures.

  • break: Used to exit a loop or switch block immediately.

  • continue: Skips the current iteration of a loop.

  • goto: Transfers control to a labeled statement.

  • return: Exits a function and optionally returns a value.

3. Storage Classes and Scope

These define the lifetime and visibility of variables:

  • auto: Default storage class for local variables.

  • static: Preserves variable value between function calls or limits scope to a single file.

  • extern: Indicates that a variable is defined in another translation unit.

  • register: Suggests to the compiler to store the variable in a CPU register.

4. User-Defined and Derived Types

  • struct: Groups variables of different types under one name.

  • union: Allows storing different data types in the same memory location.

  • enum: Defines a set of named integer constants.

  • typedef: Creates an alias for an existing data type.

5. Qualifiers and Miscellaneous

  • const: Variables whose value cannot be modified after initialization.

  • volatile: Informs the compiler that a variable's value can change unexpectedly (e.g., via hardware).

  • sizeof: An operator that returns the size (in bytes) of a type or variable.

  • signed and unsigned: Modifiers to specify if a type can hold negative values.

  • short and long: Modifiers to change the storage size (e.g., long int might be 64 bits).

6. Modern C Extensions (C99 and C11)

  • inline: Used for function optimization to reduce call overhead.

  • restrict: A qualifier for pointers to help in compiler optimization.

  • _Bool: The boolean data type.

  • _Complex and _Imaginary: Support for complex number arithmetic.

  • _Atomic: Support for thread-safe concurrent variables.

  • _Static_assert: Compile-time assertions.