Storage Classes |
Storage Place |
Default Value |
Scope |
Life-time |
auto |
RAM |
Garbage Value |
Local |
Within function |
extern |
RAM |
Zero |
Global |
Till the end of main program, may be declared anywhere in the program |
static |
RAM |
Zero |
Local |
Till the end of main program, may be declared multiple functions call |
register |
Register |
Garbage Value |
Local |
Within function |
Practice Questions:
Output:
1
2
A static count variable is initialized as 0 initially.And then incremented twice as the function is called twice.As,it is a static variable it will keep its value till the end of the program.
So,after the 1st function call, the value of count changes to 0+1=1 and then after the 2nd function call it changes to 1+1=2.
Output:
1
1
In this question,count is a local variable hence a variable will be destroyed when a function call where a variable was declared is over.Hence,value gets incremented(count++) to 1.So,after 1st function call we get value as 1 but it remains the same after 2nd function call as well.