Structured Programming and Subroutines (AQA GCSE Computer Science): Flashcards
📚Flashcards
Practise the cards
13 cards from this deck
ShowHide
Practise the cards
13 cards from this deck
Local variable definition
Local variable definition
Variable created & used inside a subroutine
Local scope meaning
Local scope meaning
Variable only exists within its subroutine
When local variable is created
When local variable is created
When the subroutine starts running
When local variable is destroyed
When local variable is destroyed
When the subroutine finishes
Can main program access local variables?
Can main program access local variables?
No, cannot see or use them
Scope definition
Scope definition
Where in program a variable can be accessed and used
Accessing local variable from outside causes
Accessing local variable from outside causes
Error - variable not defined
Error type for accessing local var from outside
Error type for accessing local var from outside
NameError: name 'variable' is not defined
Local variables benefit: organisation
Local variables benefit: organisation
Keeps code tidy, variables only used where needed
Local variables benefit: safety
Local variables benefit: safety
Can't be accidentally changed by other program parts
Local variables benefit: memory
Local variables benefit: memory
Automatically cleaned up when subroutine ends
Local variables benefit: reusability
Local variables benefit: reusability
Same var names in different subroutines don't interfere
How to pass data into subroutines
How to pass data into subroutines
Use parameters
