Embedded C and C++ Programming Questions
Coding for resource-constrained and real-time hardware in C and C++: register and hardware access, the const and volatile qualifiers, embedded coding patterns, and compiler pragmas, together with the performance-and-safety discipline embedded work demands: memory management under tight budgets, struct packing and memory layout, code-size optimization, hardware-level atomicity, and synchronization primitives for inter-task communication. Covers the language-level discipline where every construct maps to hardware behavior, plus reasoning about deterministic timing, footprint, and safe concurrency on microcontrollers and real-time systems. Distinct from general C/C++ in its hardware-facing constraints.
You must choose between implementing object pools (fixed-size preallocated objects) or an optimized dynamic allocator for a new embedded module under a tight deadline. As tech lead, present a decision memo: criteria you would evaluate, preferred choice with reasons, migration path, and how to mitigate long-term maintainability risks.
Given the following code (simplified): 'typedef struct Node { char *name; uint8_t flags; } Node; Node *list = malloc(n * sizeof(Node)); for each node name = strdup(input);' Estimate total memory usage including heap overhead for n=100 where average name length is 20 bytes. Propose concrete changes to reduce heap overhead without losing functionality.
Implement a compact allocator that supports splitting and coalescing free blocks using boundary tags. Provide C-style pseudocode for malloc() and free() operating within a contiguous heap region. Constraints: minimize per-block overhead (aim for 8-16 bytes), support alignment to 8 bytes, and attempt to limit external fragmentation.
Propose a practical static-analysis and runtime-instrumentation plan to catch memory issues (leaks, use-after-free, double-free, stack overflow) early in an embedded firmware project. Include tools to run on host, unit-tests, and on-target diagnostics for low-memory devices.
Formally quantify external fragmentation for a simple free-list allocator. Given heap size H and maximum alloc request size M, produce an expression or bound for worst-case wasted memory, and explain assumptions. How could you instrument runtime to measure fragmentation in the field?
Unlock Full Question Bank
Get access to all Embedded C and C++ Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.