static, extern, const & volatile in C

From the C cheat sheet · Storage Classes & Qualifiers · verified Jul 2026

static, extern, const & volatile

Control storage duration and access.

c
// Quick Reference
static int counter;   // file scope OR persistent local
extern int shared;    // defined in another file
const int MAX = 100;  // read-only
volatile int reg;     // do not optimize accesses
💡 A static local keeps its value between calls; a static global/function is file-private.
⚡ extern declares a variable defined in another file - shares one instance across units.
📌 const makes a value read-only; combine with pointers carefully (const int * vs int * const).
🟢 volatile tells the compiler a value can change externally (memory-mapped I/O, signals).
staticexternconstvolatile
Back to the full C cheat sheet