AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Know that subroutines may declare their own variables, called local…

    Full specification wording

    Structured programming and subroutines (procedures and functions): Know that subroutines may declare their own variables, called local variables, and that local variables usually:

    A local variable is one declared inside a subroutine and is normally accessible only within that subroutine.

    Checked against the AQA 8525 specification (opens in a new tab) on .

    • Point 5 of 9

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    A local variable is one declared inside a subroutine and is normally accessible only within that subroutine. Because it exists only while the subroutine runs, it is usually created when the subroutine is called and destroyed when it returns, so its value does not persist between calls. Two different subroutines can each use a local variable with the same name without clashing, because each has its own separate copy. This contrasts with a global variable, which is declared outside subroutines and is accessible throughout the program. Using local variables helps avoid unintended interference between parts of a program and makes subroutines easier to reuse and test. Recognise that a local variable cannot normally be read or changed by code outside its subroutine.

    What earns the marks

    • Local variables are declared inside a subroutine.
    • Their values do not normally persist between separate calls.
    • Subroutines can reuse the same local variable name without conflict.
    • Local variables differ from global variables, which are accessible throughout the program.

    Common mistakes and how to put them right

    • Thinking a local variable can be read by code outside its subroutine.

      Put it right: It is normally accessible only inside that subroutine.

    • Assuming a local variable keeps its value between calls.

      Put it right: It is usually recreated each time the subroutine runs.

    • Confusing local and global variables.

      Put it right: Local is confined to a subroutine, global is accessible throughout.

    • Believing two subroutines cannot use the same variable name.

      Put it right: Each local copy is separate, so names can repeat.

    Exam tips

    • State the scope clearly: a local variable is accessible only within its subroutine.
    • Mention lifetime: it is usually created on call and destroyed on return.
    • Contrast with a global variable to show the difference in scope and lifetime.

    Try the lesson

    The start of the Structured programming and subroutines (procedures and functions): Know that subroutines may declare their own variables, called local variables, and that local variables usually: lesson, made from checked teaching notes for this specification point.

    Have a go first

    A programmer writes a subroutine that creates a variable inside itself for its own use. What is this kind of variable called?

    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.

    Carry on with the full lesson

    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): Know that subroutines may declare their own variables, called local variables, and that local variables usually:

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge