Storage Classes in C: Auto, Extern, Static, Register
What are Storage Classes?
A storage class defines the scope, lifetime, visibility, and default value of a variable.
auto
Default storage class for local variables; created when the block starts and destroyed when it ends.
extern
Declares a global variable that is defined in another file or later in the same file.
static
Retains its value between function calls and is initialized only once.
void counter() {
static int count = 0;
count++;
printf("%d", count);
}
register
Suggests to the compiler that the variable be stored in a CPU register for faster access (modern compilers largely optimize this automatically).
PreviousRecursion in C: Types, its Working and Examples
Next Arrays in C Programming: Operations on Arrays
Ready to master real-world C Programming development?
Learn C Programming hands-on with mentor-led, live sessions.
.png)