Storage Class Interview Questions for Embedded C: Quiz and Code Challenges
63 questions: multiple choice, fill-in-the-blank, a section-matching table, true/false, 6 code challenges with real nm and size output and 12 detailed interview answers. Treat it as a model for storage class interview questions.
63
Questions
Beginner → Advanced
Level
Live score
Auto-graded
Live Score Tracker
0 Correct
0 Wrong
0 Attempted
Answer the auto-graded questions (MCQ, fill-in, true/false) to see your score.
Section 1: Multiple Choice Questions — Storage Classes and Sections
These storage class interview questions in multiple-choice form cover the vocabulary asked in nearly every embedded screening round. Click an answer; the explanation always appears.
1. Which storage class is the default for a variable declared inside a function?
Locals are auto unless declared otherwise.
2. Where does an auto variable normally live?
Automatic storage.
3. Which section holds int g = 0; (global)?
A zero initializer needs no stored image, so it goes to .bss.
4. Which section holds int g = 9; (global)?
Non-zero initial value: .data.
5. A file-scope const uint16_t tab[64] = {...}; normally consumes:
.rodata lives in flash.
6. Which statement about register is true?
The only hard rule: &x is an error.
7. Which memory needs both a flash image and SRAM at run time?
Initial values are stored in flash and copied to SRAM at reset.
8. What does the start-up code do with .bss?
This implements the zero-initialization guarantee.
9. Which command shows how much flash and SRAM sections use?
size prints text, data and bss.
10. If size reports text = 4000, data = 200, bss = 800, how much flash is needed?
Flash = text + data.
11. With those numbers, how much static SRAM is used?
Static SRAM = data + bss = 200 + 800.
12. Which declaration keeps a lookup table out of SRAM?
File-scope or static const data goes to .rodata.
13. A function declares uint8_t buf[8192]; as a normal local. The main risk is:
Large automatic arrays overflow small stacks.
14. Which symbol letter does nm print for a global in .bss?
B = bss, D = data, T = text, R = read-only data.
15. Where does the stack start on an STM32F407 with its default linker script?
The initial SP is the end of SRAM; pushes decrease the address.
Section 2: Fill in the Blanks
Spaces and capitalisation are ignored; include the leading dot where requested.
1. The default storage class of a local variable is
auto.
2. Initialized global variables are placed in the section (with the dot)
.data.
3. Zero-initialized globals are placed in the section (with the dot)
.bss.
4. Read-only constants are placed in the section (with the dot)
.rodata.
5. Machine code is placed in the section (with the dot)
.text.
6. The tool that lists symbols and their sections is
nm.
7. The tool that totals text, data and bss is
size.
8. Flash used = text +
The initial image of .data lives in flash.
9. Static SRAM used = data +
Both live in SRAM.
10. You cannot take the of a register variable
&x is an error.
11. Memory region that grows downward from the top of SRAM: the
Stack.
12. Memory region used by malloc: the
Heap.
Section 3: Which Section Does It Land In?
Pick the section for each item. This matching exercise is the most common form of storage class interview questions.
Item
Your answer
Result
int g; (file scope)
.text.rodata.data.bssStackHeap
int g = 12; (file scope)
.text.rodata.data.bssStackHeap
const int g = 12; (file scope)
.text.rodata.data.bssStackHeap
static int n; inside a function
.text.rodata.data.bssStackHeap
static int n = 1; inside a function
.text.rodata.data.bssStackHeap
int x; inside a function
.text.rodata.data.bssStackHeap
"hello" string literal in puts("hello")
.text.rodata.data.bssStackHeap
static const char name[] = "ARM"; (file scope)
.text.rodata.data.bssStackHeap
Machine code of main()
.text.rodata.data.bssStackHeap
int *p = malloc(4); (the 4 bytes pointed to)
.text.rodata.data.bssStackHeap
Section 4: True or False
Short statements typical of storage class interview questions.
1. auto is rarely written because it is already the default for locals.
True: int x; inside a function means auto int x;.
2. A static local variable is stored on the stack.
It is in .data or .bss.
3. A const local array is guaranteed to be in flash.
It is an ordinary stack variable you cannot modify. Use static const for flash.
4. .bss needs no initial image in flash.
It is simply zero-filled at reset.
5. extern int x; allocates memory for x.
It only declares the name.
6. The compiler must obey the register keyword.
It is only a hint.
7. An initialized global uses memory in both flash and SRAM.
Image in flash, working copy in SRAM.
8. The start-up code is responsible for making globals zero-initialized.
It clears .bss before main().
Section 5: Code Snippet Challenges
Real answers produced by the compiler and the binary tools make these code challenges a faithful rehearsal of storage class interview questions.
Challenge 1 — Output?: Static n and automatic m
#include <stdio.h>staticint bump(void)
{
staticint n = 10;
int m = 10;
n++; m++;
return n * 100 + m;
}
int main(void)
{
int a = bump();
int b = bump();
printf(“%d %d\n”, a, b);
return0;
}
What is printed?
Output:
1111 1211
The first call returns 11 * 100 + 11 = 1111; the second keeps n (12) but m restarts at 10 and becomes 11: 1211.
Challenge 2 — Find the bug: Taking the address of a register variable
For each array, how many bytes of flash and of SRAM does it use?
Real size output:
size
a:
text data bss dec hex filename
32 0 1000 1032 408 t.o
b:
text data bss dec hex filename
32 1000 0 1032 408 t.o
c:
text data bss dec hex filename
1032 0 0 1032 408 t.o
a (.bss): 0 flash, 1000 SRAM. b (.data): 1000 flash, 1000 SRAM. c (.rodata): 1000 flash, 0 SRAM. (The 32 bytes in the text column of a and b are object-file overhead, not part of the arrays; c shows 1032 = 1000 + the same 32.)
Challenge 6 — Find the bug: Reaching a static variable from another file
a.c:1:12: warning: ‘hidden’ defined but not used [-Wunused-variable]
1 | static int hidden = 5;
| ^~~~~~
/usr/bin/ld: file1.o: in function `main':
b.c:(.text+0x10): undefined reference to `hidden'
collect2: error: ld returned 1 exit status
hidden has internal linkage; it is not exported.
Section 6: Storage Class Interview Questions for Embedded C (with Detailed Answers)
These storage class interview questions probe whether you can connect a keyword to the memory it uses. Click a question for a model answer.
Q1. List the C storage class specifiers and say what each does.Basic+
Keyword
Effect
auto
Default for locals; automatic lifetime; stack/register
register
Hint to use a CPU register; no address-of
static
Program lifetime; internal linkage at file scope
extern
Declares an object defined elsewhere; external linkage
Q2. Explain .text, .rodata, .data and .bss.Basic+
Section
Content
Flash
SRAM
.text
Code
Yes
No
.rodata
const data, string literals
Yes
No
.data
Initialized variables
Yes (image)
Yes
.bss
Zero-initialized variables
No
Yes
Together with the stack and heap in SRAM they make up the memory layout of the program.
Q3. Where do local, global, static and constant variables live on an STM32F407?Basic+
Variable
Memory
local (auto)
Stack in SRAM (or a register)
global, non-zero init
.data in SRAM (image in flash)
global, zero or none
.bss in SRAM
static
same as global of equal initializer
const global
.rodata in flash
Q4. Is there any reason to use the register keyword today?Basic+
Almost none. Optimising compilers allocate registers better than programmers, and the keyword is only a hint. Its one enforced effect is that & cannot be applied, which can document that a variable is never aliased. Some coding standards ban it. C++17 removed it.
Q5. What does the start-up code do before main() and why?Intermediate+
It sets the stack pointer, copies the .data initial image from flash to SRAM, zeroes .bss, optionally runs C library initialization and static constructors (C++), calls SystemInit() to configure clocks and finally calls main(). Those two loops make initialized and uninitialized globals meet the C language guarantees.
Q6. Why does a large const table belong at file scope and not inside a function?Intermediate+
A file-scope const object is placed in .rodata (flash) with zero SRAM cost. A const object inside a function is an automatic variable: it is rebuilt on the stack on each call, using stack space and copy time. Use static const if you want the scope limited to the function but the data in flash.
Compare the two outputs:
static const local (real nm output)
T f -> .text
r t.0 -> .rodata
Q7. Why is initializing a big array with a single non-zero element expensive?Intermediate+
unsigned char b[4000] = {1}; is in .data: the compiler stores a complete 4000-byte image in flash (including 3999 zeros) and the start-up code copies all of it. An uninitialized array of the same size is in .bss, costing no flash. Either clear it at run time or restructure the data.
Q8. A project reports “region RAM overflowed by 2048 bytes”. How do you investigate?Intermediate+
Run arm-none-eabi-size to see data + bss, then open the .map file (or use nm --size-sort -S) to list the largest symbols. Typical culprits: big buffers that could be const or in CCM memory, duplicated tables, an oversized heap or stack reservation in the linker script, and stack arrays that were moved to globals. Remember that the linker counts only static data and the reserved heap/stack, not the real stack depth.
Q9. How do you find out how much stack a program really uses?Advanced+
Fill the stack area with a known pattern (such as 0xDEADBEEF) at start-up and later scan from the bottom for the first overwritten word: the “high-water mark”. Alternatively use compiler flags such as -fstack-usage for per-function worst case and a call-graph tool, and in an RTOS use its stack watermark API. Recursion and interrupt nesting must be added in manually.
Q10. What is CCM RAM on the STM32F407 and how would you place a variable in it?Advanced+
Core-coupled memory is a separate 64 KB SRAM at 0x10000000, directly attached to the core. It cannot be accessed by DMA, so it suits stacks, scratch data and algorithm state. In GCC you create a linker-script section (for example .ccmram) mapped to that region and write __attribute__((section(".ccmram"))) static float s_filter[256];. Variables placed there are not zeroed or initialised unless the start-up code and the linker script handle that section.
Q11. Why are static locals problematic in code shared by an ISR and the main loop (or by RTOS tasks)?Advanced+
A static local is one shared object, so the function is no longer re-entrant: an ISR interrupting the main-loop call can overwrite the state mid-update, and two tasks interleave. Fixes: pass state in through a parameter or context struct, keep one instance per task, or guard the access with a critical section.
Q12. A teammate says “all globals are initialized to zero, so I do not need to initialize them”. After moving to a bootloader-launched image, a global holds random bits. What happened?Advanced+
The language guarantee depends on the start-up code clearing .bss. If a custom reset path or bootloader jumps to the application without running the application’s own Reset_Handler (or a modified linker script moved the symbols the loop uses), .bss is not cleared. Explicit initializers are not the fix for .bss objects; the start-up sequence must be correct. Verify by checking the values of _sbss/_ebss in the map file and stepping through reset in the debugger.
Study Plan: Using Your Score on These Storage Class Interview Questions
Score
Meaning
Next step
90–100%
Excellent
Continue to Module 5: operators.
70–89%
Good
Redo Examples 1, 3, 7 and 8.
Below 70%
Revise
Re-read theory sections 1, 6, 7 and 9, then retake the quiz.
Module 4 complete: You can now declare variables, control their scope and lifetime, and predict where each one lives. Module 5 begins the operators that act on them: arithmetic, relational, logical and bitwise.
Module 4 complete!
Next up: Module 5, operators in embedded C, starting with arithmetic operators.
2 Comments