Skip to main content

Register Storage Class in C

"register" storage class in C

  • The register storage class in C is used to declare local variables that are stored in the CPU register instead of memory, and that can result in faster access times.

Syntax:

register data_type variable_name;
  • When a variable is stored in a register, the processor can access its value faster than when it is stored in memory.

  • This can be particularly beneficial for frequently used variables or loop counters, as it can result in improved performance of the program.

Example 1

#include <stdio.h>

int main()
{
register int i;
for (i = 0; i < 10; ++i)
{
printf("%d ", i);
}
return 0;
}
Output:
note

Using register storage class does not guarantee that a variable will be stored in a register, as it depends on the implementation and available registers.