0Pricing
C Academy · Lesson

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

  1. auto and Local Scope
  2. static Variables
  3. extern and Global
  4. register and const
← Back to C Academy