Storage classes in C with examples
Filed under Bosch Global Software Technologies
Free read 1 of 3A storage class decides a variable's scope, lifetime, default initial value and storage location. C has four: auto, register, static and extern.
The question
Explain the storage classes in C with an example.
Approach
A storage class decides a variable's scope, lifetime, default initial value and storage location. C has four: auto, register, static and extern.
auto is the default for local variables: stack storage, block scope, uninitialised (garbage) by default, destroyed on exit. register is a hint to keep the variable in a CPU register for speed; its address cannot be taken.
static keeps a local variable alive across calls (zero-initialised, stored in the data segment); at file scope it restricts visibility to that file. extern declares a variable defined in another file, giving it program-wide visibility.
void f(void){ auto int a = 0; static int s = 0; a++; s++; printf("%d %d\n", a, s); } Three calls print 1 1, 1 2, 1 3.
Tips
- What they are testing: Give a table-like answer: scope, lifetime, default value and memory location for each class.
- Common mistake: Saying register guarantees a register, or forgetting static variables default to zero.
Related Bosch Global Software Technologies questions
Collected from public candidate posts and coding forums. Updated Nov 2026.