Learn VisualLearn CS

How Functions and Scope Work

A function bundles up a specific piece of work. A frame is an area created for each function call to store that function's arguments and local variables. Calling another function places its frame on top, and the local variables stored in that frame are only visible within that function. The calling function can't directly see the called function's local variables; this visible range is called scope.

GOAL

Explain how each function call pushes its own frame, and how local variables are only visible within that frame.

Are add()'s variables, a, b, and sum, directly visible from main()?