C Programming · Interview question

What are the two meanings of static in C?

A strong answer

They're unrelated and depend on placement. Inside a function, static gives a local variable persistent lifetime: it's allocated in .data/.bss rather than on the stack, initialized exactly once, and retains its value across calls, but its name is still scoped to that function. At file scope, static on a global variable or function gives internal linkage: the symbol is private to its translation unit and invisible to the linker from other .c files, which is C's primary encapsulation mechanism for hiding implementation details and avoiding name collisions. So "static local" = lifetime, "static global/function" = visibility. The shared thread is "static storage duration," but the practical effect you reason about differs by context.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

const, volatile & static

Three small keywords with outsized consequences: const for intent, volatile for hardware and ISR-shared data, static for lifetime and linkage, and why volatile is not atomic.

More const, volatile & static questions

Browse all 472 interview questions