Fiveable
Fiveable

Call Stack

Definition

The call stack is a data structure that keeps track of function calls in a program. It stores information about the order and location of function calls, allowing the program to keep track of where to return after each function call is completed.

Analogy

Imagine you are at a restaurant with a limited number of tables. When you arrive, your name is added to the waiting list. As tables become available, the hostess calls out names from the top of the list and removes them. Similarly, when a function is called in a program, it gets added to the call stack. Once it completes its execution, it gets removed from the stack and control returns to where it was called from.

Related terms

Recursion: A technique where a function calls itself directly or indirectly.

Stack Overflow: An error that occurs when there are too many nested function calls or recursive calls, causing the call stack to exceed its limit.

Function Call: The act of invoking or executing a specific function in a program.

"Call Stack" appears in:



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.