AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
Are only accessible within the subroutine.
Full specification wording
Structured programming and subroutines (procedures and functions): are only accessible within the subroutine.
Local variables have limited scope: they can be read and changed only inside the subroutine in which they are declared.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 7 of 9
Study notes
From the checked teaching notes for this specification point.
The idea
Local variables have limited scope: they can be read and changed only inside the subroutine in which they are declared. Code outside that subroutine, including the main program and other subroutines, cannot refer to them by name. For example, if a procedure declares a local variable total, a line in the main program that tries to print total will fail because total is not visible there. This containment prevents accidental interference between different parts of a program and makes subroutines easier to test and reuse. Scope is about where a name can be used in the code, which is different from lifetime, the period during execution when the variable exists.
What earns the marks
- A local variable can be accessed only within the subroutine where it is declared.
- Code outside that subroutine, such as the main program or another subroutine, cannot use the local variable.
- Attempting to reference it outside its subroutine causes an error or the name is not recognised.
- Limited scope helps prevent unintended changes from other parts of the program.
- Scope (where a name is usable) is distinct from lifetime (when the variable exists during execution).
Common mistakes and how to put them right
Believing a local variable can be used anywhere in the program after it is set.
Put it right: It is accessible only inside its own subroutine.
Confusing scope with lifetime.
Put it right: Scope concerns where the name can be used in code, while lifetime concerns when it exists during execution.
Thinking two subroutines can share a local variable of the same name.
Put it right: Each subroutine's local variable is separate and not visible to the other.
Exam tips
- Name the boundary clearly: 'inside the subroutine only'.
- Give a short example of code outside the subroutine failing to access the variable.
- Use the word 'scope' precisely and separate it from 'lifetime'.
Try the lesson
The start of the Structured programming and subroutines (procedures and functions): are only accessible within the subroutine. lesson, made from checked teaching notes for this specification point.
Have a go first
A programmer declares a variable inside a subroutine. What is the scope of this variable?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Structured programming and subroutines (procedures and functions): are only accessible within the subroutine.
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge