The Call Stack

Computer Science Lessons · 219K views · 2014 · 6:26

Open on YouTube

Software (other)Education & learningexplainer

Why Stack Overflow recommends it

Stack Overflow users link it when answering recursion and stack overflow questions and want a quick visual explanation of what the call stack is.

Recommended by 1 people across 1 different months, 2016 to 2021.

What it is

A short educational video on how the call stack manages procedure and function calls and the passing of parameters. It is part of the Computer Science Lessons channel and explains the idea with simple illustrations.

What people said

Recommends LismUK · 2017-06 · Stack Overflow · on “Recursion on a merge sort function is confusing”

It sounds like you're asking about a call stack [this video] , or more specifically in this case, a recursive stack [LINK] . Read about them to understand the recursion going on here.

Cites hofan41 · 2016-03 · Stack Overflow · on “Avoiding stack overflow by using setTimeout”

It normally isn't, but in the off chance you decide you need to recursively chain the same function call for long sequences this could come in handy. Stack overflow during recursive operations occurs when the amount of stack memory allocated for a particular program has been fully utilized. A sufficiently long array that is traversed recursively can cause a stack overflow. Perhaps you do not understand how the call stack [this video] works?

Cites nevets1219 · 2021-10 · Stack Overflow · on “does recursion function with no return have build stack problem?”

The stack in reference here is the "call stack" - like its name implies, it is relevant to what you are calling (e.g. parameters). Return values are stored on the heap and the call stack simply stores an address to the heap for the return value. For more information take a look at the article on Wikipedia [LINK] (there's a nice diagram for reference, with all the proper terminology). This [this video] also describes the call stack nicely. Even if the return value is null , we still have to store some reference to it for the caller to use! Let's look at an oversimplification of what happens: foo(i) { if (i == 0) { return 0 } return foo(i - 1) } Let's invoke foo(1) , here's a simplistic view of the