Automatic memory allocation |
Automatic variables are Variables local to a statement block. They are automatically allocated on the stack (computing) 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 , b); } }
Using the gcc Compiler 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.
Automatic variables will have an undefined value when declared, so it is programming practice to initialize it with valid value before using it.|
|