In this post we will discuss about static, extern and register storage classes.
But first we need understand what is the difference between life and scope :-
Important Note :-
But first we need understand what is the difference between life and scope :-
Life :-
The lifetime of variable in C language is the time, for which the variable have memory location in memory section. Its may be during the run time execution of the program or while creation or destruction of the function stack.
Scope :-
The scope of variable in C language is that part of code till which we can directly access the variable.
- Default value of static variable is zero(0) or NULL if pointer.
- We can declare a static variable, global as well as local.
Data section are divided into two things
- Initialize data section ( Data )
- Uninitialized data section ( BSS-Block started by symbol )
Scope :-
- If we declared a static variable locally then the scope is within function or block.
- If we declared a static variable globally then the scope is within that whole file.
- Life of static variable starts when program execution starts till the execution is completed.
Re-initialization is not possible for static variable because life of the variable is up to end of compilation.
Global Static variable are having internal linkage. We can access that variable with in the file.
Global Static variable are having internal linkage. We can access that variable with in the file.