Data Structures · Recursion

How factorial(n) uses the call stack

Each call to a function gets its own frame on the stack: a private copy of its parameters, its local variables, and the place to return to. Step through the program and watch frames get pushed as the recursion goes down, then popped as the answers come back up.