auto: - auto storage class - this is the default class. If we declare a variable inside a function without defining any memory, it automatically rises to an automatic variable. Simply put, we can say that a local variable (not static) is an automatic variable. the scope of an automatic variable lies within the function in which it is declared and acts before control within the function.
eg
int main() { int a =10; { int b=10; } printf("%d",b); }
In the above example, a and b are both local variables and live up to control within the main function, but the visibility of a and b in braces where they are defined. When we try to compile the code above, I got an error: - undeclared variable b.
int main() { int a =10; int *d; { int b=20; d=&b; } printf("%d",*d); }
Exit 20. because b until the control is in the main function.
static: -
When we use static (prefix) with a variable, it is alive throughout the entire program launch. means the degree of the static variable throughout the program run. the volume of the static variable in the module in which it is declared. If we used static with a global variable, then the global variable was limited to the file in which it was declared. in other words, we can say that static makes a variable or function private to the file in which it is declared.
when we initialized a static variable, then create in the data segment (.ds) or create in .bss (the initial character) of the process.
Note: - a static variable is initialized at compile time, when memory allocates it. If we do not initialize, then it is the compiler's responsibility to initialize it with Zero.
In my experience, when you create a lookup table or any table that requires a full program run and you want to make it a specific file, you declare static.
for more information see this link: http://aticleworld.com/storage-class/
source share