Revise Computing
Revision notesQuestionsFor schools
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 12

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.
  • It is generally better to use local variables and pass values as parameters where possible.

Code examples

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

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 12

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

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

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