Skip to main content

Section 5.4 Stack Frames

When running the Codelens tool, it creates a diagram like this one:
Figure 5.4.1. Stack diagram for doubleValue
This is known as a stack diagram, which shows the state of a program’s functions and variables. For each function there is a box, called a frame or stack frame, that contains the function’s parameters and variables.
The stack starts in the box for main. I can see that at the point we were at in main, x and y have been set, but z has not been initialized yet. We have not initialized z yet, because the doubleValue function was called, and now it is executing. There is a stack frame for doubleValue right below main. It is highlighted in blue to indicate that it is where execution currently is.

Note 5.4.1.

Depending on the diagram, the stack may grow up or down from main. The ones in Codelens grow down from main.
As with other memory diagrams, stack diagrams show variables and functions at a particular point in time. If you go back and run the program again in Codelens, you will see the stack diagram change as the program runs.

Checkpoint 5.4.1.

Run the codelens and answer the questions it asks you about the stack diagram.
You have attempted of activities on this page.