Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Additional Programming Techniques

local variables

Functions and Procedures: local variables

2.2.3 Additional Programming Techniques

Practise exam questions

Additional Programming Techniques — Note 9 of 12

The use of local variables within functions and procedures:

What you need to know

A local variable is defined inside a sub-program (function or procedure) and can only be used within that sub-program. Once the sub-program finishes executing, the local variable is removed from memory. This prevents naming conflicts between different parts of a program.

What to know

  • Local variables are declared inside a function or procedure.
  • They can only be accessed within the sub-program where they were created.
  • They are removed from memory when the sub-program ends.
  • Using local variables prevents naming conflicts between sub-programs.
  • If you try to use a local variable outside its sub-program, you will get an error.
  • Parameters of a function/procedure are also treated as local variables.

Code examples

Local variable example
python
def calculate_tax(price):
    tax = price * 0.2  # 'tax' is local
    return tax

result = calculate_tax(100)
print(result)  # Output: 20.0
# print(tax)  # ERROR: 'tax' is not defined here

Ready to test yourself?

Practise 2.2.3 questions
← Previous noteSub programs (functions and procedures) to produce structured code2.2.3 Additional Programming TechniquesNext note →global variables2.2.3 Additional Programming Techniques

Back to Additional Programming Techniques

Revise another OCR GCSE topic: Programming Fundamentals

Additional Programming Techniques

Note 9 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).