AQA · GCSE · Computer Science

    Course version: 8525 · Version from Sept 2020

    Only exist while the subroutine is executing

    Full specification wording

    Structured programming and subroutines (procedures and functions): only exist while the subroutine is executing

    Local variables are created when a subroutine (procedure or function) is called and destroyed when it returns, so they exist only while the subroutine is executing.

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

    • Point 6 of 9

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Local variables are created when a subroutine (procedure or function) is called and destroyed when it returns, so they exist only while the subroutine is executing. Each call gets its own fresh copy, which is why two calls to the same subroutine do not share values. For example, a function that calculates the area of a rectangle might declare a local variable area, assign length × width to it, return area, and then the variable disappears; a second call starts with a new area. This contrasts with global variables, which exist for the whole run of the program. Recognising this lifetime helps you predict what a program prints and explains why a local variable cannot be read after the call has finished.

    What earns the marks

    • Local variables are created (allocated) when the subroutine is called and cease to exist when it returns.
    • Their lifetime is limited to the execution of that one call of the subroutine.
    • Each separate call creates a new, independent copy of the local variable.
    • A local variable's value is not retained between calls and cannot be used after the subroutine has finished.

    Common mistakes and how to put them right

    • Thinking a local variable keeps its value from one call to the next.

      Put it right: Each call creates a fresh local variable, so previous values are lost.

    • Confusing lifetime with scope.

      Put it right: Lifetime is about when the variable exists during execution, while scope is about where in the code it can be accessed.

    • Assuming a local variable can be read after the subroutine returns.

      Put it right: Once the subroutine finishes, the local variable no longer exists.

    Exam tips

    • Link the answer explicitly to the moment of the call and the moment of return.
    • Use the phrase 'created when called, destroyed when it returns' to show precise understanding.
    • Contrast with a global variable in one sentence to demonstrate the distinction clearly.

    Try the lesson

    The start of the Structured programming and subroutines (procedures and functions): only exist while the subroutine is executing lesson, made from checked teaching notes for this specification point.

    Have a go first

    A local variable is created when a subroutine starts running. When does that local variable stop existing?

    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): only exist while the subroutine is executing

    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