Type Qualifiers in C

There are many different type-qualifiers in the C programming language. Here is a brief description of some type qualifiers in C (and similar languages).

Do remember the “Clockwise/Spiral Rule” – Read the type qualifiers backwards

  • int* – pointer to int
  • int const* – pointer to const int (const int* == int const*)
  • int *const – const pointer to int
  • int const *const – const pointer to const int (const int* const == int const *const)
  • int ** – pointer to pointer to int
  • int **const – const pointer to pointer to int
  • int *const * – pointer to const pointer to int
  • int const ** – pointer to pointer to const int
  • int *const *const – const pointer to const pointer to int
  • volatile int *const – constant pointer to volatile int
  • void (*signal(int, void (*fp)(int)))(int) – signal is a function passing an int and a pointer to a function passing an int returning nothing (void) returning a pointer to a function passing an int returning nothing (void)

Storage classes (listed below) come before type-qualifiers (also listed below). Only one storage class can be used when declaring a variable. Both storage and type qualifiers come before the datatype.

Storage Classes

  • auto – Stored in stack during the code-block
  • extern – Lasts the whole program, block, or compilation unit; globally visible
  • register – Stored in stack or CPU-register during the code block
  • static – Lasts the whole program, block, or compilation unit; private in program
  • typedef – The data specifies a new datatype
  • __thread – Thread-local-storage; one instance per thread
  • _Thread_local – Thread-local data

Type-Qualifiers

  • const – Value does not change; read-only
  • restrict – For the lifetime of the pointer, the object can only be accessed via the pointer
  • volatile – Optimizing-compilers must not change
  • _Atomic – Map a variable to a basic built-in type (depending on the processor) so that reading and writing are guaranteed to happen in a single instruction
Sharing: