Auto

The auto keyword is a declaration specifies which defines a local variable as having a local lifetime. This is default storage class. All variables declared are of type Auto by default.In order to Explicit declaration of variable use ‘auto’ keyword

auto int a = 10;

 Storage Memory
 Default initial Value Garbage
 Scope Local / Block Scope
 Life time Exists as long as Control remains in the block

Also Two variables are declared in different blocks , so they are treated as different variables in the program.

#include<stdio.h>
int main()
{
auto int number = 10;
{
auto int number = 20;
printf(“Inner Auto number: %d”, number);
}
printf(“\n”);
printf(“Outer Auto number: %d”, number);
return 0;
}

Advertisements

One Comment Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s