C – Register Storage Classes

Register storage classes:

  • Keyword: register
  • Memory allocation: Inside CPU registers
  • Scope: Within the block or method

Note: Register variable must be defined as local variable.

Auto v/s Register variables:

  • “auto” variables get memory in RAM
  • “register” variables get memory inside Registers.
  • “Register” variables can access much faster than “auto” variables.

Note: Repeated variables in the logic must be defined as register variables. For example “Loop counters”

Can’t we declare all variables as register?

  • No, Registers is a small memory area. Hence, we cannot store maximum number of variables into registers.
  • Only local variables and repeated variables need to store into registers.

We cannot define register variables globally:

#include<stdio.h>
register int a=30;
int main()
{
            auto int a=10;
            printf(“In main : %d \n”, a);     
            return 0;
}
Scroll to Top