Skip to content

C Storage Classes

Storage classes determine the scope, lifetime, and storage location of variables.

1. auto (Automatic)

c
void func() {
    auto int x = 10;  // local variable (auto is default)
}

2. register

c
void func() {
    register int counter;  // suggest storing in register
}

3. static

c
void func() {
    static int count = 0;  // retains value between calls
    count++;
}

4. extern

c
// file1.c
int global_var = 100;

// file2.c
extern int global_var;  // declaration

5. Summary

  • auto: local, automatic storage
  • register: fast access, local
  • static: local scope, static lifetime
  • extern: global scope, defined elsewhere

Content is for learning and research only.