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
22 practiced

Implement a first-fit allocator in C that manages a single statically reserved buffer using a free list, exposing init, alloc and free. How do you handle alignment and block splitting, what happens to fragmentation over time, and when would you accept this allocator on a small device instead of a pool?

MediumBehavioral
19 practiced

Describe a time when you found and fixed a memory-related bug in an embedded product (behavioral). Use the STAR format: Situation, Task, Action, Result. Focus on how you diagnosed the issue, tools/methods you used, trade-offs considered, and lessons learned you applied to prevent similar issues.

HardSystem Design
35 practiced

Design a linker script and startup strategy for a device that must boot a small ROM bootloader (flash 0x00000000-0x00003FFF) and then jump to an application at 0x00004000. Include handling of the vector table (copying or remapping), how to place read-only data in flash and .data in RAM, and how the bootloader should transfer control to the application safely (including stack pointer and reset handler).

EasyTechnical
32 practiced

Implement a simple fixed-size bump allocator in C for a contiguous memory pool. Provide the API: void pool_init(void* mem, size_t size); void* pool_alloc(size_t n); void pool_reset(void); The allocator does not need to free individual allocations. Ensure proper alignment for typical embedded types.

MediumTechnical
38 practiced

How would you detect stack overflow on a task stack in an RTOS and how do you decide how big each stack should be? Cover where a guard value goes, when it is checked, what you do on detection in a shipped device and how you estimate worst-case depth.

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.