Sunday 9 February 2014

Storage classes in C

Every variable in c is declared with the following syntax:


Storage_Class Data_Type Var_name=Initial_value;

However the name of Storage_class and Initial_value are optional. That mean we can declare a variable by just providing the Data_Type and the Var_Name . In such case compiler will apply the default values for Storage_Class and Initial_Value

e.g: int n;

In this case the parameters are:
Storage_Class=auto
Data_type=int
Var_name=n
Inital_Value=Garbage

How many storage classes are there in c ?
There are four storage classes in c and those are:
1. Automatic Storage Class. Keyword auto
2. Static Storage Class.  Keyword static
3. Register Storage Class. Keyword register
4. External Storage Class.  Keyword external