Sunday, 20 May 2012

What is the difference between static and auto variables?


Static variable
Auto variable
 We have to specify the storage class to make a variable static.
It is the default storage class.
If it is not assigned any value then it will give 0 as out put.
If it is not assigned any value then it will give garbage value as output.
It is visible to the block in which it is declared and also in the function where it will passed.
It is visible to the block in which the variable is declared.
It retains its value between different function calls. It holds its last value.
It retains its value till the control remains in the block in which the variable is declared.
Static variable should be compile by compiler first.
Auto variable will compile by the compiler after the static variable.

1 comment: