Exam-style question
Try this first
A programmer needs a value that is used only while one function performs a calculation. Which choice best matches the contrast between local and global variables?.
- A.Use a local variable because its access is restricted to the relevant part of the program.
- B.Use a global variable because every variable must be accessible everywhere.
- C.Use a global variable because local variables cannot store calculated values.
- D.Use a local variable because local variables are always stored as text.
Model answer
What a good answer should say
- Use a local variable because its access is restricted to the relevant part of the program.
Explanation
Why this works
When a value is needed only in one function, a local variable matches that limited use. The contrast is based on where the variable can be accessed, not on the type of data it stores.
Common mistake
No common mistake is linked to this question yet.
