Ques: Types of storage class in C?
Ans: In C there are 4 types of storage classes present
1) Auto
2) Extern
3) Static
4) Register
Auto: Auto variable are local variables define inside and function.
Any variable can be explain in this way; Scope, Lifetime, Visibility
ex: int get ()
{
int age; // automatic variable
}
Scope: within get method
Lifetime: Till get method is getting executed
Visibility : Only to get method
Ques: What is difference between static variable and volatile variable?
Ans: static Variable:
Static variable is available to the module it is defined and till compilation Unit( Same source file or module).
or
Static variable is the one that exists for the life time of compilation unit (Source file of module)
Volatile Variable:
Volatile keyword is the hint to compiler that the variable's value might change without the compiler's knowledge, therefore the compiler code optimizer can not make assumptions about the variable's current value and must always re-read the variable content.
volatile is generally used when dealing with external events, like interrupts of hardware related pins.
Note: Volatile is not a type of storage, it can be stored anywhere in the memory, volatile is just a type, So, by declaring variable as volatile.. it gives guarantee that you will get the latest value, which may be altered by an external event.
Under construction..............
Ans: In C there are 4 types of storage classes present
1) Auto
2) Extern
3) Static
4) Register
Auto: Auto variable are local variables define inside and function.
Any variable can be explain in this way; Scope, Lifetime, Visibility
ex: int get ()
{
int age; // automatic variable
}
Scope: within get method
Lifetime: Till get method is getting executed
Visibility : Only to get method
Ques: What is difference between static variable and volatile variable?
Ans: static Variable:
Static variable is available to the module it is defined and till compilation Unit( Same source file or module).
or
Static variable is the one that exists for the life time of compilation unit (Source file of module)
Volatile Variable:
Volatile keyword is the hint to compiler that the variable's value might change without the compiler's knowledge, therefore the compiler code optimizer can not make assumptions about the variable's current value and must always re-read the variable content.
volatile is generally used when dealing with external events, like interrupts of hardware related pins.
Note: Volatile is not a type of storage, it can be stored anywhere in the memory, volatile is just a type, So, by declaring variable as volatile.. it gives guarantee that you will get the latest value, which may be altered by an external event.
Under construction..............
No comments:
Post a Comment