‘auto’ keyword of C programming language

14203

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];

auto keyword Example:

                 auto int number; or
int number;

Both statement has the same meaning. As the auto keyword is the local lifetime is the default for local variables, the 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.

Attempt Free C Programming MCQ Quiz

Previous QuizKeyword in C Programming Language – definition and examples
Next Quiz‘break’ keyword in C Programming language

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.