Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).

Knowledge/A Level/H446/02 Algorithms and programming/Programming Techniques/Global and local variables

Global and local variables

Global and local variables.

2.2.1 Programming Techniques

Practise exam questions

Programming Techniques — Note 3 of 6

Candidates need to understand the difference, benefits and drawbacks of global and local variables. Candidates must be able to recognise where each is used and its impact on a program, for example the amount of memory used, and change a program from one to the other.

What you need to know

A variable's scope is the part of the program where it can be used. Global variables can be used anywhere; local variables only exist inside the subroutine where they are declared. Choosing the correct scope makes programs more reliable and easier to maintain.

What to know

  • Local variables: memory is freed when the subroutine ends; the same name can be used in different subroutines without conflict; subroutines are self-contained and easier to reuse and test. Drawback: data must be passed in as parameters and results returned, which means more code.
  • Global variables: useful for values needed throughout the program (e.g. settings), but they can be changed accidentally anywhere, making bugs hard to find, and they stay in memory for the whole run. Saying globals 'use more memory' is credited, but explain it as lifetime: a global is no bigger than a local, but a local's memory is freed when its subroutine ends.
  • If a local variable has the same name as a global one, the local variable is used inside the subroutine.
  • Parameters are local variables of their subroutine. In a recursive subroutine each call gets its own copy of its parameters and locals (its own stack frame). A global would be shared by every call, so each call would overwrite the last one's value and the algorithm would have to change.
  • Good practice: use local variables and pass data through parameters; keep global variables to a minimum.

Key terms

Global variable

A variable whose scope is the whole program, so it can be accessed anywhere, including inside subroutines. OCR pseudocode declares it with the global keyword, e.g. global userid = 123.

Local variable

Declared inside a subroutine; it only exists while the subroutine runs and can only be accessed within it.

Exam technique

  • Tip:Develop each benefit or drawback into its consequence, e.g. a global changed in one subroutine causes an unexpected side effect elsewhere, so the bug is harder to find and test. 'It can be changed accidentally' on its own gets little credit.
  • Tip:In the long comparison of globals and locals, go beyond definitions. Apply scope and parameter passing (by value or by reference) to the scenario's own data, note whether the program may grow or uses recursion, and end with a justified recommendation.
  • Tip:Be able to change a program that uses global variables into one that uses local variables and parameters, and vice versa.

Past exam questions

  • June 2026Paper 2Q8(b)(i)2marks
  • June 2026Paper 2Q8(b)(ii)2marks
  • June 2025Paper 2Q6(b)(i)2marks
  • June 2025Paper 2Q6(b)(ii)2marks
  • June 2025Paper 2Q6(b)(iii)2marks
  • June 2024Paper 2Q9(f)9marks
  • June 2023Paper 2Q9(f)9marks
  • June 2022Paper 2Q1(c)2marks
  • November 2021Paper 2Q8(c)9marks
  • June 2018Paper 2Q4(c)9marks

Ready to test yourself?

Practise 2.2.1 questions
← Previous noteRecursion, how it can be used and how it compares to an iterative approach2.2.1 Programming TechniquesNext note →Modularity, functions and procedures, parameter passing by value and by reference2.2.1 Programming Techniques

Back to Programming Techniques

Programming Techniques

Note 3 of 6

  1. 1Programming constructs: sequence, iteration, branching
  2. 2Recursion, how it can be used and how it compares to an iterative approach
  3. 3Global and local variables
  4. 4Modularity, functions and procedures, parameter passing by value and by reference
  5. 5Use of an IDE to develop/debug a program
  6. 6Use of object oriented techniques
Topic overview