Quiz- Storage Class Interview Questions for Embedded C: Quiz and Code Challenges-Free Embedded C Course Online

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

MODULE 4 · LESSON 4.3 · PRACTICE

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?

2. Where does an auto variable normally live?

3. Which section holds int g = 0; (global)?

4. Which section holds int g = 9; (global)?

5. A file-scope const uint16_t tab[64] = {...}; normally consumes:

6. Which statement about register is true?

7. Which memory needs both a flash image and SRAM at run time?

8. What does the start-up code do with .bss?

9. Which command shows how much flash and SRAM sections use?

10. If size reports text = 4000, data = 200, bss = 800, how much flash is needed?

11. With those numbers, how much static SRAM is used?

12. Which declaration keeps a lookup table out of SRAM?

13. A function declares uint8_t buf[8192]; as a normal local. The main risk is:

14. Which symbol letter does nm print for a global in .bss?

15. Where does the stack start on an STM32F407 with its default linker script?

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

2. Initialized global variables are placed in the section (with the dot)

3. Zero-initialized globals are placed in the section (with the dot)

4. Read-only constants are placed in the section (with the dot)

5. Machine code is placed in the section (with the dot)

6. The tool that lists symbols and their sections is

7. The tool that totals text, data and bss is

8. Flash used = text +

9. Static SRAM used = data +

10. You cannot take the of a register variable

11. Memory region that grows downward from the top of SRAM: the

12. Memory region used by malloc: the

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.

ItemYour answerResult
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.

2. A static local variable is stored on the stack.

3. A const local array is guaranteed to be in flash.

4. .bss needs no initial image in flash.

5. extern int x; allocates memory for x.

6. The compiler must obey the register keyword.

7. An initialized global uses memory in both flash and SRAM.

8. The start-up code is responsible for making globals zero-initialized.

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> static int bump(void) { static int 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); return 0; }

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
#include <stdio.h> int main(void) { register int hits = 0; int *p = &hits; *p += 3; printf(“%d\n”, hits); return 0; }

What does GCC say?

GCC output:
bug.c: In function ‘main’:
bug.c:6:5: error: address of register variable ‘hits’ requested
    6 |     int *p = &hits;
      |     ^~~
Remove register and let the compiler decide.
Challenge 3 — Classify: Which sections?
int coeff[3] = { 1, 2, 3 }; const int limit = 100; static int count; int total = 0; int scale = –1;

Give the section of each of the five variables.

Real nm output:
nm
D coeff -> .data b count -> .bss R limit -> .rodata D scale -> .data B total -> .bss
total is initialised to zero, so it goes to .bss; scale = -1 is non-zero, so .data; limit is .rodata; count is a file-local .bss symbol.
Challenge 4 — Output?: Static call counter
#include <stdio.h> static void show(void) { static int calls; printf(“%d “, ++calls); } int main(void) { for (int i = 0; i < 4; i++) show(); printf(“\n”); return 0; }

What does the program print?

Output:
1 2 3 4 
The static is zero at start and keeps counting.
Challenge 5 — Estimate: Three 1000-byte arrays
unsigned char a[1000]; unsigned char b[1000] = { 1 }; const unsigned char c[1000] = { 1 };

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: static int hidden = 5; int visible = 6; b.c: extern int visible; extern int hidden; int main(void) { return visible + hidden; }

What does the linker report?

Linker output:
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+
KeywordEffect
autoDefault for locals; automatic lifetime; stack/register
registerHint to use a CPU register; no address-of
staticProgram lifetime; internal linkage at file scope
externDeclares an object defined elsewhere; external linkage
Q2. Explain .text, .rodata, .data and .bss.Basic+
SectionContentFlashSRAM
.textCodeYesNo
.rodataconst data, string literalsYesNo
.dataInitialized variablesYes (image)Yes
.bssZero-initialized variablesNoYes

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+
VariableMemory
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
staticsame 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

ScoreMeaningNext step
90–100%ExcellentContinue to Module 5: operators.
70–89%GoodRedo Examples 1, 3, 7 and 8.
Below 70%ReviseRe-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.

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *