Home / Learn Embedded C / Explaining volatile in an Interview
Explaining volatile in an Interview
A model answer for one of the single most commonly asked embedded C interview questions.
How to think about this
What it is
A strong interview answer on volatile explains WHAT it does (tells the compiler a variable can change outside the compiler's visible control flow, preventing it from being cached/optimized away), WHY it matters (ISR-shared data, memory-mapped hardware registers), and ideally a concrete example of a bug it prevents.
Why it matters
volatile is arguably the single most frequently asked embedded C concept in interviews specifically because it sits at the intersection of language knowledge and genuine hardware understanding — a good answer demonstrates both, not just a memorized definition.
Mechanically speaking
The strongest answers go beyond the bare definition to give a specific, concrete scenario (an ISR-set flag the main loop polls, or a memory-mapped status register) showing the concept is genuinely understood, not simply memorized from a textbook.
Shows up in
- Common interview question preparation
- Demonstrating depth of understanding
- C language fundamentals review
Try it
In real C this flag would be declared volatile (unsupported in this sandbox, see JSCPP_NOTES.md) so the compiler cannot cache a stale value across the ISR boundary; describing exactly this scenario is what makes an interview answer concrete rather than textbook-generic.
Try it: the memory-mapped register scenario, the other classic example
This is the second classic volatile scenario interviewers expect: a memory-mapped status register that hardware can change at any time, so the compiler must never cache a stale copy of it.
Check yourself
1. What makes an interview answer about volatile genuinely strong, rather than merely adequate?
A strong answer goes beyond the bare definition to show genuine understanding through a concrete, realistic example of where and why volatile actually matters.