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.

Quick summaryA 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

The exact ISR-shared-flag scenario a strong answer would describeC: edit and run

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.

Tip:When asked to explain volatile, structure the answer in three parts: what it does, why it matters (a concrete scenario), and ideally mention its limitation (it does not guarantee atomicity, just preventing unwanted caching) — this shows depth beyond a memorized definition.

Try it: the memory-mapped register scenario, the other classic example

A status register that must be re-read every time, not cachedC: edit and run

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?