Local and global variables (Edexcel GCSE Computer Science): Flashcards
📚Flashcards
Practise the cards
14 cards from this deck
ShowHide
Practise the cards
14 cards from this deck
Scope in programming
Scope in programming
Area of a program where a variable can be accessed and used
Local scope
Local scope
Area within a single subprogram
Local variable
Local variable
Variable created inside a subprogram
Local variable accessibility
Local variable accessibility
Only within the subprogram where created
What happens to local variables after subprogram ends?
What happens to local variables after subprogram ends?
They disappear
Global scope
Global scope
Covers the entire running program
Global variable
Global variable
Variable accessible from anywhere in program
Global variable accessibility
Global variable accessibility
Main program and all subprograms
Duration of global variables
Duration of global variables
Entire duration of the program
Variable lookup order
Variable lookup order
Local scope first, then global scope
Why local scope checked first
Why local scope checked first
Prevents local variables being overwritten by globals
Same-named vars in different scopes
Same-named vars in different scopes
Can exist without interfering with each other
total used inside doAvg() in example
total used inside doAvg() in example
Local version (starts at 0)
total used in main program in example
total used in main program in example
Global version (154)
