Exam-style question
Try this first
Which statement best contrasts a local variable with a global variable?.
- A.A local variable can be used throughout the whole program, while a global variable can be used only inside one function.
- B.A local variable is available only within its defined local section, while a global variable is available from a wider part of the program.
- C.A local variable must contain text, while a global variable must contain a number.
- D.A local variable is created before a program starts, while a global variable is created only inside a function.
Model answer
What a good answer should say
- A local variable is available only within its defined local section, while a global variable is available from a wider part of the program.
Explanation
Why this works
The key difference is scope. A local variable is restricted to the part of the program where it is defined, whereas a global variable can be accessed from a wider part of the program.
Common mistake
No common mistake is linked to this question yet.
