ProgrammingTopic Summary

Knowledge Organiser: Variable Scope

Part of Variable Scope · GCSE GCSE Computer Science revision

This topic summary covers Knowledge Organiser: Variable Scope 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 7 of 7 in this topic. Use this topic summary to connect the idea to the wider topic before moving on to questions and flashcards.

Topic position

Section 7 of 7

Practice

15 questions

Recall

10 flashcards

Knowledge Organiser: Variable Scope

Key Terms
  • Scope: The region of code where a variable can be seen and used
  • Local variable: Declared inside a subprogram; accessible only within that subprogram
  • Global variable: Declared outside all subprograms; accessible anywhere in the program
  • Lifetime: How long a variable exists — local variables are created when the function runs and destroyed when it ends
Must-Know Facts
  • Local variables cannot be accessed outside the subprogram they are declared in
  • Global variables exist for the entire runtime of the program
  • Local variables are more memory-efficient — they are freed when the function ends
  • Parameters are local to the function they belong to
  • Best practice: use local variables wherever possible — safer and tidier
  • Accessing a local variable outside its function causes a runtime error
Key Concepts
  • Declare global: global score = 0
  • Declare local: local bonus = 10 inside a function
  • Global can be read and modified from any subprogram
  • Local is created on function call, destroyed on function return
Common Mistakes
  • Trying to use a local variable outside its function: Local variables only exist inside the subprogram where they are declared — accessing them elsewhere causes a runtime error
  • Assuming global variables are always better: Global variables can be accidentally modified by any part of the program — local variables are safer and preferred where possible
  • Forgetting local variables are destroyed after function ends: Local variables do not retain their value between function calls — a new copy is created each time the function runs
  • Confusing scope with data type: Scope (local/global) describes WHERE a variable is accessible; data type (integer/string) describes WHAT it stores — these are separate concepts
Unit 2.3: Robust Programs

Revise this topic interactively on PrepWise — self-test mode, tap-to-reveal definitions, and Common Mistakes from examiners.

Try the interactive Knowledge Organiser — free →

Keep building this topic

Read this section alongside the surrounding pages in Variable Scope. That gives you the full topic sequence instead of a single isolated revision point.

Practice Questions for Variable Scope

Where can a local variable be accessed?

  • A. Anywhere in the program
  • B. Only within the subprogram where it is declared
  • C. Only in the main program body
  • D. In any subprogram that calls the original subprogram
1 markfoundation

Identify and explain the scope error in this pseudocode: function calculateTotal(price, quantity) local total = price * quantity endfunction calculateTotal(10, 5) output total

2 marksstandard

Quick Recall Flashcards

What is variable scope?
Where a variable can be accessed in the code
What is a global variable?
A variable declared outside all subprograms, accessible anywhere in the program

15 questions on Variable Scope — practise free

Instant marking, adaptive difficulty, and 10 spaced repetition flashcards. Free until your GCSEs.

Try PrepWise Free