auto:

In C programming language an auto keyword defines a local variable storage class that has a local or limited lifetime from the end of its declaration to the end of its enclosing scope (block or function); once program flow exit that scope, that instance of the variable ceases to exist.

Syntax ‘auto’ keyword in the C Programming language:

                  Auto [data_type] [variable_name];

Example:

                 auto int number; or
int number;

Both the statement has the same meaning. As auto keyword is the local lifetime is the default for local variables, auto keyword is extremely rarely used it’s only meaningful to a compiler-writer or interpreter developer making an entry in a symbol table or better readability auto keyword can be used. Auto keyword says this storage is automatically allocated on entering the block (as opposed to global static allocation, or dynamic allocation on the heap). Auto is irrelevant to other programmers, since you get it by default.

C Program of ‘auto’ keyword:

Program:

#include <stdio.h>
#include <conio.h>
void main()
{
auto int i=10;
clrscr();
{
auto int i=20;
printf(“\n\t %d”, i);
}
printf(“\n\n\t %d”,i);
getch();
}

Output:           20   10

Note: GNU C extends auto keyword to allow forward declaration of nested functions.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here