Embedded C interview questions and answers for firmware roles

Embedded C interview questions focus on the parts of C that behave differently when the code drives hardware: fixed-width integer types, volatile register access, bit masks and read-modify-write, integer promotion, interrupt service routines and data shared with them, and memory without a heap. Expect short snippets to debug, a register driver or fixed-point routine to write, and questions about what the compiler is allowed to do with your code. Strong answers tie every rule to a real failure on a device.

By Published 11 min read

What "embedded C" means in an interview

Embedded C is ordinary ISO C written for a microcontroller: no operating system or a small RTOS, kilobytes of RAM, memory-mapped peripherals and interrupts that can fire between any two instructions. Interviewers for firmware, embedded software, automotive, IoT and hardware test roles use it to check whether you know which language rules matter on that kind of machine. If you need a refresher on pointers, strings and struct padding first, start with C interview questions; the system side (RTOS, buses, power) is covered in embedded systems interview questions.

  1. Rapid-fire language checksvolatile, const, static, fixed-width types, and what a given expression evaluates to on a 16-bit or 32-bit target.
  2. Write a small driver or helperSet and clear register fields, parse a byte frame, implement a fixed-point multiply or a debounce routine, usually without a compiler.
  3. Find the bugA snippet that works at -O0 and fails at -O2, an ISR that loses counts, or a timeout that misfires after the timer wraps.
  4. Design talkHow you would structure firmware so it can be unit-tested on a PC, and how you avoid dynamic memory.

Embedded C fundamentals questions

First-round questions and what interviewers listen for
QuestionWhat it testsWhat a strong answer shows
Why use uint8_t, uint16_t and uint32_t instead of int?PortabilityThe size of int depends on the target (16 bits on some small MCUs, 32 on most ARM parts). Registers and protocols have fixed widths, so the types must too.
What does volatile tell the compiler?OptimizationThat every read and write is observable, so it must not cache the value in a register, merge accesses or drop a write. Use it for hardware registers and variables changed by an ISR.
What does volatile not do?Common misconceptionIt does not make an access atomic, does not stop the CPU or other cores from reordering memory operations, and is not a lock. Those need critical sections, atomics or barriers.
Can a variable be both const and volatile?QualifiersYes: a read-only status register. Your code may not write it, but its value can change at any time.
Where do const tables live?Memory mapUsually in flash (.rodata), which saves RAM. A lookup table missing const may be copied into RAM at startup.
What happens before main() runs?StartupThe reset handler sets the stack pointer, copies initialized globals from flash to RAM (.data), zeroes uninitialized ones (.bss), configures clocks on some platforms, then calls main.
Why do many firmware projects avoid malloc?DeterminismHeap allocation can fragment over long uptimes and its timing is unpredictable. Static allocation or fixed-size pools make memory use known at link time.
#define, const or enum for constants?Style and safetyenum and static const carry types and show in a debugger; #define is untyped text substitution. Register addresses and masks are still commonly macros.
Are C bit-fields good for describing registers?PortabilityTheir bit order, padding and access width are implementation-defined, so many teams use masks and shifts for registers and keep bit-fields for internal data.
What does a static variable inside a function mean in firmware?StorageIt keeps its value between calls and lives in .data or .bss, not on the stack. It also makes the function non-reentrant if an ISR calls it too.
First-round questions and what interviewers listen for. Scroll sideways on a small screen.

Register access and bit manipulation

#include <stdint.h>
#include <stdio.h>

/* On a real MCU the pointer would be a fixed address from the datasheet,
   for example #define UART0 ((uart_regs_t *)0x40001000u). */
typedef struct {
    volatile uint32_t CTRL;   /* offset 0x00 */
    volatile uint32_t STATUS; /* offset 0x04 */
    volatile uint32_t DATA;   /* offset 0x08 */
} uart_regs_t;

#define CTRL_EN          (1u << 0)
#define CTRL_BAUD_SHIFT  4u
#define CTRL_BAUD_MASK   (0x7u << CTRL_BAUD_SHIFT)

static uart_regs_t fake_uart;
#define UART0 (&fake_uart)

/* Read-modify-write of one field without disturbing the other bits. */
static void uart_set_baud_index(uint32_t idx)
{
    uint32_t v = UART0->CTRL;
    v &= ~CTRL_BAUD_MASK;
    v |= (idx << CTRL_BAUD_SHIFT) & CTRL_BAUD_MASK;
    UART0->CTRL = v;
}

int main(void)
{
    UART0->CTRL = 0x0000F0F0u;
    UART0->CTRL |= CTRL_EN;          /* set a bit */
    uart_set_baud_index(5u);         /* write a 3-bit field */
    printf("CTRL = 0x%08lX\n", (unsigned long)UART0->CTRL);
    printf("enabled = %d\n", (UART0->CTRL & CTRL_EN) != 0);
    UART0->CTRL &= ~CTRL_EN;         /* clear a bit */
    printf("CTRL = 0x%08lX\n", (unsigned long)UART0->CTRL);
    printf("offsetof DATA = %lu\n",
           (unsigned long)((char *)&fake_uart.DATA - (char *)&fake_uart));
    return 0;
}
A peripheral as a struct of volatile registers, with set, clear and field writes. Compiled with gcc -std=c11 -Wall -Wextra and run on a PC (the struct stands in for the hardware address). It prints CTRL = 0x0000F0D1, enabled = 1, CTRL = 0x0000F0D0 and offsetof DATA = 8.
  • Why is `REG |= BIT` not always safe? It is a read, a modify and a write. If an ISR changes another bit of the same register between the read and the write, that change is lost. Disable the interrupt around it, or use set/clear registers or bit-banding if the chip offers them.
  • What is a write-one-to-clear flag? A status bit cleared by writing 1 to it. Doing STATUS |= FLAG reads every pending flag and writes them all back as ones, clearing flags you never handled. Write only the bit you mean: STATUS = FLAG.
  • Why must the mask be unsigned? 1 << 31 on a 32-bit int shifts into the sign bit, which is undefined behavior. 1u << 31 is defined.
  • How do you check that only one bit is set? x != 0 && (x & (x - 1)) == 0. It is the same test as "is a power of two" and shows up in buffer-size checks.
  • Why put registers in a struct instead of separate address macros? One base address per peripheral instance, offsets checked by the compiler, and the same driver works for UART0 and UART1 by passing a pointer.
  • Should a register access be inside a macro or an inline function? Static inline functions type-check their arguments and are easier to step through; macros are still common in vendor headers.

Integer traps interviewers love

#include <stdint.h>
#include <stdio.h>

int main(void)
{
    /* 1. ~ promotes uint8_t to int before inverting. */
    uint8_t flags = 0xFF;
    printf("~flags == 0: %d\n", ~flags == 0);
    printf("(uint8_t)~flags == 0: %d\n", (uint8_t)~flags == 0);

    /* 2. Signed meets unsigned: -1 converts to a huge unsigned value. */
    int offset = -1;
    unsigned int len = 1u;
    printf("offset < len: %d\n", offset < len);

    /* 3. Tick counters: the naive sum wraps, the subtraction does not. */
    uint32_t start = 0xFFFFFFF0u;   /* counter is about to wrap */
    uint32_t timeout = 32u;
    uint32_t now = 0xFFFFFFF8u;     /* only 8 ticks have passed */
    printf("naive expired: %d\n", now >= start + timeout);
    printf("wrap-safe expired: %d\n", (uint32_t)(now - start) >= timeout);
    return 0;
}
Three classic surprises. Compiled with gcc -Wall -Wextra, which warns on the first two; the run prints ~flags == 0: 0, (uint8_t)~flags == 0: 1, offset < len: 0, naive expired: 1, wrap-safe expired: 0.
  • Why is `~flags == 0` false for a byte of all ones? Integer promotion turns the uint8_t into an int before ~, so the result has ones in the upper bits. Cast back to uint8_t, or compare with masks.
  • Why does the timeout fire after 8 ticks? start + timeout overflowed and wrapped to a small number. Unsigned subtraction now - start gives the elapsed ticks correctly across one wrap, so compare elapsed time with the timeout.
  • What can go wrong multiplying two uint16_t values? On a 32-bit-int target both promote to signed int, and 0xFFFF * 0xFFFF overflows a signed int, which is undefined. Cast one operand to uint32_t first.
  • Is right-shifting a negative number portable? The result is implementation-defined (most compilers do an arithmetic shift). Shifting by the type's width or more is undefined. Keep shifts on unsigned values.
  • Is `char` signed? It depends on the target and compiler; some ARM toolchains make plain char unsigned. Use int8_t or uint8_t for data.
  • What order are function arguments evaluated in? Unspecified. A call such as log(read_fifo(), read_fifo()) can read the FIFO in either order, so take values into variables first.

Interrupts, shared data and memory

static volatile uint32_t rx_bytes;   /* written by the ISR */
static volatile bool rx_overflow;

void UART0_IRQHandler(void)          /* keep it short: count and flag */
{
    rx_bytes++;
    if (rx_bytes > 1000u) rx_overflow = true;
}

uint32_t take_rx_bytes(void)         /* main-loop side */
{
    uint32_t saved = irq_save();     /* read and reset as one step */
    uint32_t n = rx_bytes;
    rx_bytes = 0;
    irq_restore(saved);
    return n;
}
Sharing a counter between an ISR and the main loop. irq_save and irq_restore stand for your platform's primitives; on a PC they were stubs, so this compiled and ran (printing 3 0) but the interrupt behavior itself was not exercised on hardware.
Intermediate questions on ISRs and memory
QuestionWhat it testsWhat a strong answer shows
What should an ISR do and avoid?ISR designClear the source, move data to a buffer, set a flag and return. Avoid blocking calls, printf, malloc, long loops and floating point on cores where the ISR would have to save FPU state.
Why is volatile not enough for rx_bytes above?AtomicityThe main loop reads and then zeroes it in two steps; an interrupt in between loses a count. On an 8-bit MCU even reading a 32-bit value takes several instructions and can tear.
Why save and restore the interrupt state rather than just enable at the end?NestingIf interrupts were already disabled by the caller, blindly enabling them breaks the caller's critical section.
What is a reentrant function?ConcurrencyOne that is safe if interrupted and called again before finishing: no static or global state without protection, no non-reentrant library calls.
How do you size the stack?MemoryStatic analysis of the call tree from the toolchain, plus ISR depth, then measure by filling the stack with a pattern and checking how much was overwritten after a stress run.
What happens on stack overflow on a bare-metal MCU?Failure modeOften silent corruption of .bss or the heap, then a crash far away. A memory protection unit guard region or a stack limit register, where available, turns it into a clean fault.
How do you place a variable in a specific memory region?ToolchainA compiler attribute naming a section, plus a matching region in the linker script. Used for DMA buffers, no-init RAM that survives reset, or fast RAM.
What is a weak symbol used for in startup code?LinkingDefault interrupt handlers are declared weak so your own function with the same name replaces them without editing the vector table.
Intermediate questions on ISRs and memory. Scroll sideways on a small screen.

Senior embedded C and scenario questions

#include <stdint.h>
#include <stdio.h>

/* Q15: a signed 16-bit value that represents -1.0 to just under +1.0. */
typedef int16_t q15_t;

static q15_t q15_mul(q15_t a, q15_t b)
{
    int32_t p = (int32_t)a * b;          /* widen first: 16x16 needs 32 bits */
    p += 1 << 14;                        /* round to nearest */
    p >>= 15;
    if (p > INT16_MAX) p = INT16_MAX;    /* only -1.0 * -1.0 lands here */
    return (q15_t)p;
}

static double q15_to_double(q15_t v) { return v / 32768.0; }

int main(void)
{
    q15_t half = 16384, quarter = 8192, minus_one = INT16_MIN;
    printf("0.5 * 0.25 = %.5f\n", q15_to_double(q15_mul(half, quarter)));
    printf("-1 * -1 saturates to %.5f\n", q15_to_double(q15_mul(minus_one, minus_one)));

    /* Without the cast, two uint16_t operands promote to (signed) int. */
    uint16_t a = 0xFFFF, b = 0xFFFF;
    uint32_t safe = (uint32_t)a * b;
    printf("0xFFFF * 0xFFFF = 0x%08lX\n", (unsigned long)safe);
    return 0;
}
Q15 fixed-point multiply with rounding and saturation, for cores without a floating-point unit. Compiled and run on a PC: 0.5 * 0.25 = 0.12500, -1 * -1 saturates to 0.99997, and 0xFFFF * 0xFFFF = 0xFFFE0001 with the cast.
  • The firmware works at -O0 and hangs at -O2. Where do you look? A flag polled in a loop without volatile (the compiler hoists the read out of the loop), undefined behavior the optimizer exploited, a missing memory barrier around DMA, or a timing assumption that the faster code breaks.
  • How do you serialize a struct for a radio or UART protocol? Not with memcpy of the struct: padding and byte order differ between targets. Write each field byte by byte with shifts in the protocol's defined order, and parse it the same way.
  • DMA wrote a buffer but the CPU reads stale data. Why? On cores with a data cache the CPU may read cached lines. Invalidate the cache for that buffer after the transfer (and clean it before a transmit), or place DMA buffers in non-cacheable memory.
  • What are MISRA C rules for, and how do you treat them? A widely used guideline set for safety-related C, popular in automotive and industrial work, that bans or restricts risky constructs. Teams enforce it with static analysis and document justified deviations. Mention it only as far as you have used it.
  • How do you unit-test embedded C on a PC? Keep hardware access behind a thin layer of functions, build the logic for the host with a test framework, and replace the hardware layer with fakes. Hardware-in-the-loop tests then cover the drivers.
  • How would you shrink a binary that no longer fits in flash? Read the map file to find the biggest symbols, drop printf-style formatting, use size optimization and link-time optimization, remove unused sections, and move large tables to const.
  • How do you debug a hard fault? Capture the stacked registers in the fault handler, find the faulting program counter in the map file or debugger, and check for null or misaligned pointers, stack overflow and calls through a corrupted function pointer.

Fictional example

Answering "Our button counter sometimes misses presses"
Interviewer
An ISR increments a 32-bit press counter on a GPIO edge. The main loop reads it, sends it over UART and sets it back to zero. On the 8-bit board some presses go missing. Why?
Candidate
Two problems are likely. First, on an 8-bit core a 32-bit read takes several instructions, so an interrupt in the middle can give a torn value. Second, the read and the reset are separate steps, so a press that arrives between them is wiped out. I would make the read-and-reset a critical section by saving and disabling interrupts around it, keeping that window a few instructions long, and make sure the counter is volatile so the loop really re-reads it. I would also ask whether the button is debounced, because contact bounce could make the count noisy in the other direction. To prove the fix, I would drive the pin from a signal generator at a known rate and compare counts over a long run.

Embedded C practice plan

  • Days 1 and 2: write register helpers for an imaginary peripheral from a made-up datasheet table: set, clear, field write, and write-one-to-clear handling.
  • Days 3 and 4: compile small programs with all warnings on and predict each promotion and signedness result before running them.
  • Day 5: write the wrap-safe timeout, a fixed-point multiply and a byte-order-independent frame parser, with tests on your PC.
  • Day 6: read a real linker map file from an example project and explain .text, .rodata, .data and .bss sizes.
  • Day 7: mock round: explain volatile, atomic access and ISR rules aloud, then debug a seeded snippet without a compiler.

Role-level preparation, including how the whole loop runs, is on embedded software engineer interview questions.

Embedded C answers fall apart when you jump to a fix before naming the rule, such as integer promotion or a torn read. Natively, an AI interview assistant for Mac and Windows, writes up a mock firmware round as a transcript on your computer, so you can check whether you explained the cause before the cure. In practice it can read a C snippet or a register table from a screenshot and ask what the code does on a 16-bit target, and with Pro or the free trial it can use your résumé and the job description you add. Session notes are kept for review.

Questions people ask

What embedded C questions are asked in interviews?

Why fixed-width types matter, what volatile does and does not do, const and volatile together, register access with masks and shifts, read-modify-write races, integer promotion, wrap-safe timeouts, ISR rules, atomic access, startup code and why firmware avoids malloc.

What is the use of volatile in embedded C?

It tells the compiler every access is observable, so it must re-read and re-write the variable each time. Use it for memory-mapped registers and variables changed by an ISR; it does not make accesses atomic.

How is embedded C different from C?

The language is the same ISO C. The difference is the environment: fixed memory, no or a small operating system, hardware registers, interrupts and strict timing, which make certain rules (volatile, integer widths, no heap) central.

How should I prepare for an embedded C interview?

Write register helpers and a fixed-point routine by hand, compile small programs with all warnings on to learn promotion rules, read a linker map file, and practice explaining ISR and shared-data bugs out loud.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP