Practice question · Put in order
Order what happens when the call f(3, 4) is evaluated.
- The function returns its result to the caller
- The function's local variables cease to exist
- The arguments are bound to the function's parameters
- The body runs, creating local variables as it goes
- The caller evaluates the arguments 3 and 4
Hints
- Nothing can enter the function before the caller has values to pass.
- The locals outlive the body but not the return.
Show the answer
- The caller evaluates the arguments 3 and 4
- The arguments are bound to the function's parameters
- The body runs, creating local variables as it goes
- The function returns its result to the caller
- The function's local variables cease to exist
Why
Arguments are evaluated, bound to parameters, the body runs, a value comes back, and the locals vanish. That last step is encapsulation in action: the internals are gone, so only the returned value can influence the caller.
Practise Functions and Modularity
The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Functions and Modularity
- A function that reads no globals and changes nothing outside itself is called pure. Why do such functions…
- Sort each change to a function by whether existing callers keep working untouched.
- If two different functions each define a local variable named count, changing one of them changes the other.
- Extracting repeated code into a function usually makes a program longer, not shorter, once the definition and…