Local and global variables (Edexcel GCSE Computer Science): Flashcards

📚Flashcards
Local and global variables
Sign up to keep revising.Create a free account to study more flashcards and track your progress.

Practise the cards

14 cards from this deck

Show

Scope in programming

Area of a program where a variable can be accessed and used

Local scope

Area within a single subprogram

Local variable

Variable created inside a subprogram

Local variable accessibility

Only within the subprogram where created

What happens to local variables after subprogram ends?

They disappear

Global scope

Covers the entire running program

Global variable

Variable accessible from anywhere in program

Global variable accessibility

Main program and all subprograms

Duration of global variables

Entire duration of the program

Variable lookup order

Local scope first, then global scope

Why local scope checked first

Prevents local variables being overwritten by globals

Same-named vars in different scopes

Can exist without interfering with each other

total used inside doAvg() in example

Local version (starts at 0)

total used in main program in example

Global version (154)

Join 100,000+ GCSE students studying Flashcards with us.

Select your subjects, and get access to A+ resources today.