This study notes covers Local vs Global within Variable Scope for GCSE Computer Science. Revise Variable Scope in Programming for GCSE Computer Science with 15 exam-style questions and 10 flashcards. This topic appears less often, but it can still be a useful differentiator on mixed-topic papers. It is section 3 of 6 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.
Topic position
Section 3 of 6
Practice
15 questions
Recall
10 flashcards
Local vs Global
| Aspect | Local Variable | Global Variable |
|---|---|---|
| Declared | Inside a subprogram | Outside all subprograms |
| Accessible | Only within that subprogram | Anywhere in the program |
| Lifetime | Created when function runs, destroyed when it ends | Exists for entire program |
| Memory | Efficient - freed when not needed | Uses memory entire time |
| Safety | Can't be accidentally changed elsewhere | Can be changed from anywhere |