Global and Local Variables (OCR A-Level Computer Science): Flashcards

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

Practise the cards

15 cards from this deck

Show

Variables (definition)

Named storage locations in memory used to hold data

Scope (definition)

Where a variable can be accessed within a program

Global variables (definition)

Variables declared outside any function, class, or block

Global variables: scope

Accessible from any part of the program

Global variables: lifetime

Exist for the entire duration of the program

Local variables (definition)

Variables declared within a function, class, or block

Local variables: scope

Accessible only within the block/function where defined

Local variables: lifetime

Exists only while the function or block is executing

Global vs local: memory usage

Global occupy memory throughout; local memory freed after use

Global variables: benefit (data sharing)

Useful for data accessed & modified by multiple functions

Global variables: drawback (errors)

Accidental modification can lead to unintended behaviour

Local variables: benefit (memory)

Memory allocated & freed dynamically, reducing consumption

Local variables: drawback (access)

Cannot be accessed outside their defining function or block

Shadowing (definition)

Local variable with same name as a global variable

Converting global to local: method

Pass it as a parameter to functions that need it

Explore OCR A-Level Computer Science Revision Notes by Topics

Explore OCR A-Level Computer Science Model Answers by Topics

Explore OCR A-Level Computer Science Quizzes by Topics

Explore OCR A-Level Computer Science Exam Questions by Topics

Join 100,000+ A-Level students studying Flashcards with us.

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