Whenever we talk of variables or data types the various concepts that are immediately associated with it are: 1. The name of the variable 2. The amount of space required to store that variable 3. Address of the memory location where the variable is created 4. The possible operations, which can be performed with the variable
However, we never considered the permanence of a variable or its scope i.e. the portion of the program where the variable is valid or recognized. All these factors are considered with storage classes.
In C, variables differ in behavior from those in most of the other languages. A variable in C can have anyone of the four storage classes: 1. Automatic Storage class 2. External Storage class 3. Static Storage class 4. Register Storage class
There are many ways in which a storage class can be identified. Sometimes a storage class can be established by just identifying the location of he declaration of the variable. In other situations a storage class is identified with the help of certain keywords before the variable declaration.
1. Automatic Storage Class: A variable is said to belong to the automatic storage class if the validity or scope of the variable is limited to only the function in which it has been defined. Automatic variables are declared inside the function in which they are to be utilized. They are created when the function is called and destroyed automatically when the function is called and destroyed automatically when the function is exited, hence the name automatic. Automatic variables are therefore local to the function in which they are declared. Because of this property, automatic variables are also referred to as local or internal variable. A variable declared inside a function without storage class specification is, by default, an automatic variable. One can use the keyword auto to make the storage class explicit by no one does main( ) { auto int