Storage class explain the behavior of the variable in
terms of scope and lifetime, it also determine the initial of the variable. Scope of the variable is the region over which the variable is visible or valid. Life time of the variable is the time during which memory is associated with the variable. Initial value is the value assigned to the variable implicitly if no value is assigned to it by the programmer. There are four types of storage class available in C: Auto Extern Static Register Auto
All local variables has this storage class.
Default value is the garbage value. Scope of the variable is only between the blocks where it is declared. Lifetime is till the control remains within the block or function where these variables are defined. These variables are destroyed whenever block ends or function jump occur. To declare auto storage class auto keyword is used. Example: auto int n; Auto keyword is optional all the local variables by default fall under this storage class. Example: int n; Extern
Scope is through out the program.
Lifetime is till the end of the program. Initial value is 0. Extern keyword is used to declare the variable of this storage class. extern int x; By default global variable has this storage class. Static
It is special case of local variable.
These are defined inside the function or block. Its scope is inside the block or the function where it is defined. Initial value is 0. Its value is retained between different function calls. Lifetime is same as the global variable i.e. through out the program. Keyword static is used to define this type of variable. Register
Register variable behave in every way same as the
auto variable. The only difference is that register variable are store inside the computer register instead of the memory. They are used when CPU has to access the variable very frequently. Eg looping variable They are defined by placing keyword register before the datatype of variable. Example register int a=10;