Storage Classes:- Not only is data required to declare a variable, but its storage class also has to be mentioned. (or)
The variables declared in C programs are different from other languages. We can use the same variable names in the C program in separate blocks. When we declare a variable, it is available only to a specific part or block of the program. The remaining block or other function cannot get access to the variable.
A storage class of variable tells us four things:
Where the variable would be stored.
The Scope of the variable, i.e., in which region of the program the value of a variable is actually available for us active.
Life of the variable, i.e., how long the variable, i.e., how long the variable would be active in the program(longevity or alive).
The initial value of the variable if it is not initialized.
Any variable declared in C can have any one of the four storage classes:
1) Automatic variables: These are defined inside a function. A variable declared inside a function
without storage class name, by default, is an auto variable. The keyword used to declare these variables is “static.”
2)External variables: These are also known as global variables. These variables are declared
outside the function and the values of these variables are available to all the functions of the
3)Static variables: This may be Local (or) global depending upon where it is declared. If it is
declared outside the function, it is static global otherwise, if it declared inside a function
block, it is static local. A static variable is initialized only once and can never be re-initialized. The value of static variable persists at each call, and the last change made in the variable remains throughout the program execution.
4) Register Variables: Instead of storing in memory, variables can also be stored in a CPU register. The advantage of storing in registers is register access is faster than memory access so, generally, frequently accessed variables are kept in registers for faster execution of the program.