Tuesday 20 June 2017

Storage class specifier

Storage class specifiers tells the compiler where to store a variable, how to store the variable, what is the initial value of the variable and life time of the variable. 

Types of storage class specifier in c :

 There are four storage class specifier in C Language. They are,
1. Automatic
2. Register
3. Static
4. Extern

S.No.
Storage Specifier
Storage place
Initial / default value
Scope
Life
1
auto
CPU Memory
Garbage value
local
Within the function only.
2
extern
CPU memory
Zero
Global
Till the end of the main program. Variable definition might be anywhere in the C program
3
static
CPU memory
Zero
local
Retains the value of the variable between different function calls.
4
register
Register memory
Garbage value
local
Within the function


    • For faster access of a variable, it is better to go for register specifiers rather than auto specifiers.
    • Because, register variables are stored in register memory whereas auto variables are stored in main CPU memory.
    • Only few variables can be stored in register memory. So, we can use variables as register that are used very often in a C program.

No comments:

Post a Comment