Storage class defines the Life Span or Visibility of the variables and functions. Basic four different storage classes in a C program which is listed below:
The auto storage class is the default storage class for all the local variables.
auto int no;
Above defines two different variables within the same storage class. 'auto' can only be used in functions.
The register storage class used for local variable and that can only stored in the. Register storage class size depands on the means that the variable has a maximum size equal to the register size (usually one word) and can't have the unary '&' operator applied to it.
The register can only used for variables that require quick access. Register should also be highlight that defining 'register' does not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register depending on hardware and implemention of them.
The static storage class is used to instructing the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.
static int count = 5;
When variable define as a static that means that can never change, modified and declare as same name.
The extern storage class is used to give a reference of a global variable that is visible hroughout the ALL program . When you use 'extern', the variable cannot be initialized, it points the variable name at a storage location that has been previously defined.
When you have multiple files and you define a global variable or function, which will also be used in other file, then extern will be used in another file to provide the reference of defined variable or function.