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
GCSE Computer Science/Paper 2/Additional Programming Techniques

global variables

Functions and Procedures: global variables

2.2.3 Additional Programming Techniques

Practise exam questions

Additional Programming Techniques — Note 10 of 13

The use of global variables within functions and procedures:

What you need to know

A global variable is defined in the main program (outside any sub-program) and can be accessed from anywhere in the program, including inside functions and procedures. While useful for sharing data, overusing global variables can make programs harder to debug and maintain.

What to know

  • Global variables are declared in the main program, outside of any function or procedure.
  • They can be accessed from anywhere in the program, including inside sub-programs.
  • In OCR pseudocode, use the global keyword: global userID = "Cust001".
  • In Python, use the global keyword inside a function to modify a global variable.
  • Overusing global variables can make code harder to debug and maintain: because ANY part of the program can change a global, it is harder to find where a wrong value came from.
  • It is generally better to use local variables and pass values as parameters where possible.

Code examples

Global vs local variable (OCR Exam Reference Language)
text
global score = 0              // global variable

procedure addPoints(points)
    score = score + points    // changes the global
endprocedure

addPoints(10)
addPoints(5)
print(score)                  // 15
Global vs Local variable
python
score = 0  # Global variable

def add_points(points):
    global score
    score = score + points  # Modifies the global

add_points(10)
add_points(5)
print(score)  # Output: 15

Exam technique

  • Mistake:Thinking a global variable is a constant. Any part of the program can still CHANGE a global variable; a constant, such as const vat = 0.2, can't be changed once it is set.

Ready to test yourself?

Practise 2.2.3 questions
← Previous notelocal variables2.2.3 Additional Programming TechniquesNext note →arrays2.2.3 Additional Programming Techniques

Back to Additional Programming Techniques

Revise another OCR GCSE topic: Programming Fundamentals

Additional Programming Techniques

Note 10 of 13

  1. 1Concatenation
  2. 2slicing
  3. 3ASCII Conversion
  4. 4Open, Read, Write, Close
  5. 5Records to store data
  6. 6SQL to search for data
  7. 7one-dimensional (1D)
  8. 8two-dimensional arrays(2D)
  9. 9Sub programs (functions and procedures) to produce structured code
  10. 10local variables
  11. 11global variables
  12. 12arrays
  13. 13Random number generation
Topic overview

© 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).