Structured Programming and Subroutines (AQA GCSE Computer Science): Flashcards

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

Practise the cards

13 cards from this deck

Show

Local variable definition

Variable created & used inside a subroutine

Local scope meaning

Variable only exists within its subroutine

When local variable is created

When the subroutine starts running

When local variable is destroyed

When the subroutine finishes

Can main program access local variables?

No, cannot see or use them

Scope definition

Where in program a variable can be accessed and used

Accessing local variable from outside causes

Error - variable not defined

Error type for accessing local var from outside

NameError: name 'variable' is not defined

Local variables benefit: organisation

Keeps code tidy, variables only used where needed

Local variables benefit: safety

Can't be accidentally changed by other program parts

Local variables benefit: memory

Automatically cleaned up when subroutine ends

Local variables benefit: reusability

Same var names in different subroutines don't interfere

How to pass data into subroutines

Use parameters

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

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