Debugging and call stacks

Debugging's purpose is to show you enough information about your program to enable you to find the bugs. One way it does this is to show you a call stack. This is a data structure which holds the records of the functions as they are called. Usually they are shown in the order of calling. When a function is on the 'top' of the stack (may be the bottom of the list on the screen) it is the one executing. When it finishes by returning, its record is removed from the call stack.

The call stack is real, not just something made up for the debugger. It is how computers keep track of where they are executing, what variables are in scope, what the return value for the function is. They can help you understand how your program is operating "I didn't think that function got called there!" "The return value is what?"

Call stacks grow as functions call functions. They shrink as functions finish their work and return.

There is a little more about call stacks in the Notes, chapter 12 about Recursion, near the bottom of the page.