Exam-style question
Try this first
What happens if a program attempts to use a local variable outside the subroutine in which it was declared?.
- A.The variable is not accessible from that location
- B.The variable automatically becomes a global variable
- C.The variable keeps its final value and is available everywhere
- D.The variable is copied into every other subroutine
Model answer
What a good answer should say
- The variable is not accessible from that location
Explanation
Why this works
Local variables have scope limited to their own subroutine. Code outside that subroutine cannot access them as local variables.
Common mistake
No common mistake is linked to this question yet.
