They differ in removal order. A stack is LIFO, last in, first out: you push and pop at the same end (the top), so the most recently added item comes out first. A queue is FIFO, first in, first out: you add at the back and remove from the front, so the oldest item comes out first. Both are abstract access disciplines, not storage layouts, you can back either with an array or a linked list; what defines them is the order elements leave. The practical consequence: a stack reverses the order of what you put in, a queue preserves it. You pick based on semantics, a stack for "most recent first" (undo, call frames, backtracking), a queue for "process in arrival order" (event handling, ISR-to-main byte passing).
Data Structures & Algorithms · Interview question
What's the difference between a stack and a queue?
A strong answer
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
How would you implement a queue efficiently, and what's the naive mistake?Give a concrete embedded use for a stack and one for a queue.What does "peek" do, and why does the distinction from "pop" matter?What bounds must you check on a fixed-capacity stack or queue?An ISR enqueues bytes into a ring-buffer queue and the main loop dequeues them. Do you need a lock?How would you implement a FIFO queue using only two stacks, and what's the cost?
Browse all 472 interview questions