Automatic variable
Appearance
Automatic Variables: Variables local to a block are called automatic variables. They are automatically allocated on the stack when that block of code is entered. When the block exits, the variables are automatically deallocated.
for example, try the following code:
main() { { int a; a = 10; } { int b; printf("b = %d\n", b); } }
On most compilers (read gcc) this will give the output
b = 10
because the same memory location that was allocated to a is allocated to b when the second block is entered.
That reminds me. Automatic variables will have a garbage value when declared. Better initialize it with valid value before using it.