Embedded C and C++ Programming Questions

Writing C and C++ for resource-constrained microcontrollers and bare-metal or RTOS firmware, where every language construct maps to hardware behavior. Covers the C and C++ language craft firmware code relies on (header guards and the one-definition rule, macros versus const, inline and constexpr, enum class, callback and dispatch tables, static locals, const-correctness, bounded string handling, compile-time lookup tables, and overridable default handlers through weak symbols), the const and volatile qualifiers, memory-mapped register access (including bitfield versus mask-and-shift modelling) and read-modify-write patterns, compiler pragmas and optimization flags, packing structs to match hardware register and wire layouts, linker scripts, memory maps, placement across flash, SRAM, tightly coupled and backup memory, and startup code, static versus dynamic allocation, memory pools, bump, first-fit, buddy and slab embedded allocators, heap fragmentation, out-of-memory strategy and finding leaks or heap corruption without desktop tools, DMA-safe buffer allocation, stack sizing and overflow detection, memory protection unit regions for isolating tasks, fixed-point arithmetic, code-size reduction, the cost of C++ features such as exceptions, virtual dispatch and templates in firmware, and whether a given access is atomic on the target hardware (word size, read-modify-write on registers). Boundary: general-purpose C++ application craft (STL containers and algorithms, template metaprogramming), language-defined struct padding rules, inline assembly, interrupt and real-time scheduling theory, general concurrency primitives, peripheral buses and drivers, assembly-level debugging, and firmware architecture and ring-buffer streaming are covered elsewhere.

MediumTechnical
30 practiced

Explain how a linker script decides where code, initialised data and uninitialised data land on a microcontroller. Show how you would keep a diagnostics buffer out of the startup zeroing so it survives a warm reset, and how C code finds the boundaries of a section.

EasyTechnical
19 practiced

Show in C how you would declare a callback type and keep several callbacks in a table that a driver walks. Why are function pointer tables common in firmware, and what can go wrong when the table or a target lives in a different memory region?

MediumTechnical
23 practiced

Write a bounded string copy for firmware that never overruns its destination, always terminates the result and tells the caller whether it truncated. What undefined behaviour does it avoid, and why is it suitable for a constrained target?

HardSystem Design
30 practiced

Could a compacting allocator make sense on a 64 KB microcontroller with no MMU? Describe how it would work, how pointers stay valid, what pause times to expect, and when you would rather use a simpler non-moving allocator.

MediumTechnical
21 practiced

A shipped device uses malloc and free freely and starts failing allocations after weeks of uptime. How would you migrate it to a safer allocation scheme with minimal code churn, and how do you de-risk the rollout on devices in the field?

Unlock Full Question Bank

Get access to all Embedded C and C++ Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.