Free taster
5 of 6 sections open
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
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
This topic in real past papers
Every real exam question we've found on variable scope, with a full worked answer.