Variable Scope

Computer ScienceOCRGCSEUnit: 3.2 Programming
Free taster
5 of 6 sections open
The basics

Where Variables Live

Where Variables Live

Scope is where a variable can be seen and used. A local variable is like your bedroom - only you can access it, and when you leave, it's cleaned up. A global variable is like the living room - everyone in the house can use it, and it's always there. Local variables exist only inside their function. Global variables exist everywhere. Generally, prefer local - it's tidier and safer!

What is a global variable?: A variable declared outside all subprograms, accessible anywhere in the program
Key terms

Computer Science glossary

What is a global variable?
A variable declared outside all subprograms, accessible anywhere in the program

Now try it yourself

Quiz · Question 1 of 18

Where can a local variable be accessed?

Tap an answer to check it

Revise every Computer Science topic, free during alpha

Variable Scope is one of 60 topics on PrepWise — all aligned to your exam board.

Start revising free →