Storage Class in C
Storage class refers to the performance of a variable and its scope and lifetime within the program. It is associated with variable for describing the scope of the variable.
We can use these storage class before the identifier during the declaration of a variable.
There are four different storage class specification.
- automatic
- external
- static
- register
automatic storage class
Automatic variable does not retain its value once control is transferred out of its defining function. Any value assigned to an automatic variable within a function will be lost once the function is exited. Automatic storage class is by default in the C language. It doesn't need to use during declaration time.
external storage class
The scope extends from point of definition through the remainder of program. They are often referred to as global variables. External variables are recognized globally, they can be accessed from any function.
static storage class
In a single-file program, static variables are defined within individual function and therefore have the same scope as automatic variable, they are local to the function in which they are defined.
Unlike automatic variable, static retain their value.
register storage class
The storage class is implemented for classifying local variable whose value needs to be saved in a register in place of RAM.
Register variables are used when implementing looping in counter variable to make program execution fast. Register variable works faster than variable stored in RAM.