Practice question · True or false
If two different functions each define a local variable named count, changing one of them changes the other.
Hints
- Ask which function each name belongs to.
- Locals are created fresh each time a function runs.
Show the answer
False
Why
False. Each function's count is a separate variable that exists only during that function's execution, so they cannot collide. This independence is what allows functions written by different people to be combined safely.
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.
- Order what happens when the call f(3, 4) is evaluated.
- Extracting repeated code into a function usually makes a program longer, not shorter, once the definition and…