auto and Local Scope
Block-level variables.
What Is Scope
Scope is the region of code where a name is visible. In C, variables declared inside a block are visible only within that block.
#include <stdio.h>
int main(void) {
int x = 5;
printf("x = %d\n", x);
return 0;
}The auto Storage Class
Local variables are auto by default. The keyword is rarely written because it is implied for every block-scope variable.
#include <stdio.h>
int main(void) {
auto int n = 42;
printf("n = %d\n", n);
return 0;
}All lessons in this course
- auto and Local Scope
- static Variables
- extern and Global
- register and const