Auto Storage Class
1. Auto variables are declared in the function in which they are to be utilized. For example :
The scope of variable a is in function1 only . As the execution counter will come out of function1 variable a will get destroyed .
2. Visibility of auto variable is within the block where it has declared. For example :
3. Scope of auto variable is within the block where it has declared.
4. Default initial value of auto variable is garbage.
5. An auto variable gets memory at run time.
Static Storage Class
1. The value of static variable persist until the end of program .
2. Static variables are initialized only once , when the program is compiled .
3. It may be of external or internal depending on the place of their declaration .
4. Internal Static variables are those which are declared inside a function .
5. An external static variable is declared is declared outside of all the function .
Please comment if you like the above post or find any mistake .
1. Auto variables are declared in the function in which they are to be utilized. For example :
void function1() {
int a = 20;
printf("%d", a);
}
The scope of variable a is in function1 only . As the execution counter will come out of function1 variable a will get destroyed .
2. Visibility of auto variable is within the block where it has declared. For example :
#include<stdio.h>
int main(){
int a=10;
{
int a=20;
printf("%d",a);
}
printf(" %d",a);
return 0;
}
Output : 20 10.3. Scope of auto variable is within the block where it has declared.
4. Default initial value of auto variable is garbage.
5. An auto variable gets memory at run time.
1. Also known as global variables.
2. Declared outside to any function . for example :
#include <stdio.h>
int i; //By default it is extern variable
int main(){
printf("%d",i);
return 0;
}
3. These variables are active and alive throughout the entire program.
4. When we use extern modifier with any variables it is only declaration i.e. memory is not allocated for these variable.
#include <stdio.h>
extern int i; //extern variable
int main(){
printf("%d",i); // Compilation error beacuse extern vaibale does not get memory.
return 0;
}
Register Storage Class
1. These variables are stored in of the machine's register and are declared using register keyword for eg.
register int count.
2. In following declaration : register int a;
In the above point we are only requesting not forcing to compiler to store variable a in CPU. Compiler will decide where to store in the variable a.
3. A register variable execute faster than other variables because it is stored in CPU so during the execution compiler has no extra burden to bring the variable from memory to CPU.
4. Since a CPU have limited number of register so it is programmer responsibility which variable should declared as register variable i.e. variable which are using many times should declared as a register variable.
5. We cannot dereference register variable since it has not any memory address.
6. Default initial value of register variable is garbage.
7. Scope and visibility of register variable is block.
Static Storage Class
1. The value of static variable persist until the end of program .
2. Static variables are initialized only once , when the program is compiled .
3. It may be of external or internal depending on the place of their declaration .
4. Internal Static variables are those which are declared inside a function .
5. An external static variable is declared is declared outside of all the function .
Please comment if you like the above post or find any mistake .
No comments:
Post a Comment