Storage class in C:

The storage class is used to define the scope, life time and visibility of the variable. There are four types of storage class in C programming language.

  • Auto
  • Extern
  • Register
  • Static

Auto :

Auto is the default storage class for all the variables. This keyword may not required because by default all the variable will append with this auto keyword.

Examle:

 

Extern:

Extern keyword used to give reference to the global variables into another file. So we can access the other file’s global variables into another file. Whatever changes made in that variable will impact with all the variables.

 

Register:

Variable which declared with register keyword that instruct your compiler to store the variable in register memory instead of store into RAM memory . It increases your program execution speed. The variable which named as register which doesn’t have memory location. So we cannot use unary operator(&) to the register variable. Also there is no assurance the variable will always store in the register memory. It may depends on your operating system level and hardware restrictions.

 

Static :

The variable which is named as static inside the local variable it will keep the variable life time until the complete program execution completes. It will not create and destroy each time execution of the code. If the global variable which is declared as static it restrict the access in the other files.

output:

count value is : 1

count value is : 2

count value is : 3

count value is : 4

count value is : 5