Automatic Variables

The variables local to a function are automatic i.e., declared within the function. The scope of lies within the function itself. The automatic defined in different functions, even if they have same name, are treated as different. It is the default storage class for variables declared in a function.

Points to remember:

• The auto is optional therefore there is no need to write it.
• All the formal arguments also have the auto storage class.
• The initialization of the auto-variables can be done:
in declarations
using assignment expression in a function
• If not initialized the unpredictable value is defined.
• The value is not retained after exiting from the program.

Let us study these variables by a sample program given below:

/* To print the value of automatic variables */
# include <stdio.h>
main ( int argc, char * argv[ ])
int a, b;
double d;
printf(“%d”, argc);
a = 10;
b = 5;
d = (b * b) – (a/2);
printf(“%d, %d, %f”, a, b, d);

All the variables a, b, d, argc and argv [ ] have automatic storage class.

Leave a Reply

Your email address will not be published.

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

%d bloggers like this: