Auto:Storage Classes

Estudies4you
Auto:


Variables with automatic storage duration are created when the block in which they’re defined is entered; they exist while the block is active, and they’re destroyed when the block is exited.
Only variables can have automatic storage duration.
A functions local variables (those declared in the parameter list or function body) normally have automatic storage duration.

Keyword auto explicitly declares variables of automatic storage duration.
#include<stdio.h>
#include<conio.h>
void fun();
int main()
{
auto int a;
clrscr();
a=10;
printf(“a=%d\n”,a);
{
int a=20;
printf(“a=%d\n”,a);
}
printf(“a=%d\n”,a);
fun();
printf(“a=%d\n”,a);
getch();
return 0;
}
void main()
{
int a=30;
printf(“a=%d\n”,a);
}


OUTPUT:
a=10
a=20
a=10
a=30
a=10
For example, in the program shown on the screen the following declaration indicates that int variable ‘a’ is an automatic local variable and exists only in the body of the function or the block in which the declaration appears:
auto int a;
local variables have automatic storage duration by default, so keyword auto is rarely used.


To Top