Data Structures & Algorithms · Interview question

Give a concrete embedded use for a stack and one for a queue.

A strong answer

Stack: the hardware call stack is the canonical one, each function call pushes a frame (locals, return address) and each return pops it, which is pure LIFO. Beyond that, an explicit stack is used to evaluate expressions, match brackets / validate the nesting of a protocol frame, and do depth-first traversal or backtracking, often deliberately as an explicit stack in RAM to avoid deep recursion overflowing the limited hardware stack. Queue: an ISR-to-main-loop handoff, the UART RX interrupt enqueues received bytes (or events) into a ring buffer and the main loop dequeues them in arrival order, decoupling the fast producer from the slower consumer. Event loops and task ready-lists are queues for the same reason: things must be handled in the order they arrived.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Stacks & Queues

LIFO stacks and FIFO queues: the two access disciplines behind the call stack, expression evaluation, and ISR-to-main event passing, and how to back each with fixed memory.

More Stacks & Queues questions

Browse all 472 interview questions
Give a concrete embedded use for a stack and one for a queue. | EmbeddedPrep.io