AUTO STORAGE CLASS

Auto storage class:

The location of the auto storage class is memory. The default initial value is garbage value, which is unpredictable.  The variable will be alive until the block in which the variable is defined in under the phase of execution. The variable scope is upto to the block in which it is defined.

Example:

#include <stdio.h>

int main()

{  

    auto int i;

    printf("%d",i);

    return 0;

}

Output:

When it is compiled in the  standard turbo c compiler, it will give an garbage value.

Else when it is compiled in online compilers it will the output as zero.

Reference:

https://www.onlinegdb.com/online_c_compiler

Scope of auto storage class:

The scope of auto storage is up to the block in which it is defined.

Example:

Output:

321

Explanation:

the execution starts from the block 3 as it is closed 1st and return 3 to the console, and then it will clears the value 3 from the memory. Then goes to 2nd block and prints 2 and then kills the memory. Then goes to 1st block and prints 1 and then kills the variable and clears the memory allocated to it.

 

Contributor's Info

Created:
0Comment