C Basics · beginner · ~10 min
Understand block, function, and file scope.
A variable's scope is where in the code its name is visible; its lifetime is when its storage exists.
{} has block scope and dies when the block ends.static to make it private to the file; without it, the name is exported.static int g_count = 0; // file-private global
int next_id(void) {
int local_id = ++g_count; // local, dies at function return
return local_id;
}