Whenever we declare a variable in our program there comes an idea of a variable's visibility. Then we think about what will be its initial value? In c every variable have its storage class. Four types of storage classes in c:
- Automatic
- Static
- Extern
- Register
Automatic storage class( variable) : Automatic variable's visibility can be within block of local function. And it will be stored in stack segment. All local variables resides in stack segment and belongs to automatic storage class. Initial value of automatic variable will be garbage.
Static storage class(variable) : Static variable will be visible within block of local function or within block of function. It will be stored in data segment. All static variables resides in data segment block. Initial value of static variable will be 0. And keeps updated value.
Extern storage class(variable) : Extern variable used to link a variable within multiple files. Scope or visibility of extern variable is globally. It is also stored in data segment. Initial Value of extern variable is also 0.
Register storage class(variable): Register variable stored in CPU register. When we declare a register variable Compiler check if there is any CPU register available for that variable then it will stored in register. But we haven't get acknowledgement if this variable get register or not. Most important thing is We can not use & to scan a register variable like other variables.
Error using '&':
Here is an example of storage classes:
Comments
Post a Comment