The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Auto Storage Class

What Is Auto Storage Class?

  • All variables declared inside a function without any storage classes keyword is considered as auto storage class by default.
  • In auto storage class a memory is allocated automatically to the variables when the function is called and deallocates automatically when the function exits.
  • Variables under auto storage classes are local to the block or function. So, it is also called as local variables.
  • The keyword auto is rarely used because all uninitialized variables are said to have auto storage classes.
Auto Storage Class

Syntax - Auto Storage Class

Syntax
auto int m1;

C program - Auto Storage Class

auto.c
#include <stdio.h>
int main()
{
//declaration of automatic variables within main function
auto int m1 = 5;     //declaration of automatic variable with the keyword auto
int m2 = 10;      //declaration of automatic variable without the keyword auto
printf("The value of m1 : %d ", m1);
printf("\nThe value of m2 : %d ", m2);
return 0;
}
  • The value of m1 : 5
  • The value of m2 : 10

Note:

The automatic variables are declared and initialized inside the main function.

Reference?

Keyword auto
Storage Type Memory
Scope Block Scope
Life Time Static life time
Visibility Local/Global
Default Value Garbage value
Default Storage Class Yes

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report