Exam-style question
Try this first
Explain two benefits of using local variables in subroutines. Your answer should refer to accessibility and the effect on program development or reliability.
Model answer
What a good answer should say
- A local variable is accessible only within the subroutine that declares it, so other parts of the program cannot accidentally change it.
- It exists only while that subroutine is executing, which limits its use to the task for which it is needed.
- Using local variables can make a program easier to understand because the data used by a subroutine is kept with that subroutine.
- It can also improve reliability by reducing unintended interference between different subroutines.
Explanation
Why this works
Full credit should identify restricted accessibility and limited existence, then link these properties to good practice such as clearer subroutines, reduced accidental changes, or improved reliability.
Common mistake
No common mistake is linked to this question yet.
