Automatic Storage Class in C programming

This is a storage class for local variables. That means these types of variables are defined within a block or function and their scope exists within the block or function in which they are defined. That means any automatic variables behave like any other normal local variable. A keyword ‘auto’ is appended before a variable declaration of local variable to indicate that they are local variables. When a variable is declared as a local, it is saved in the memory – RAM. That is, a memory address is allocated to the variable and is henceforth called by variable name. This type of variables will have garbage values in it unless and until they are initialized. Hence they are not different from any other local variables.

#include 

void main(){
	auto int intNum;

	printf("\nValue at intNum before initializing is %d ", intNum);// shows compilation error that intNum is not initialized

	intNum = 100;
	printf("\nValue at intNum after initializing is %d ", intNum);
}

If we initialize the value and try to execute the program, it will work without any errors. This implies that, auto creates a memory space for the variable intNum, but it does not allow to use the variable until it is initialized.


Next > < Prev
Scroll to Top