Global and Local Variables (OCR A-Level Computer Science): Quizzes
📚Quizzes
Practise the questions
12 questions from this quiz
ShowHide
Practise the questions
12 questions from this quiz
What does the scope of a variable determine?
What does the scope of a variable determine?
Where it can be accessed in a program
Where are global variables declared?
Where are global variables declared?
Outside any function, class, or block
How long do global variables exist?
How long do global variables exist?
For the entire duration of the program
Where can local variables be accessed?
Where can local variables be accessed?
Only within their defining function/block
When is memory freed for local variables?
When is memory freed for local variables?
Once the function/block ends
How long do global variables occupy memory?
How long do global variables occupy memory?
Throughout program execution
Which variables are harder to debug?
Which variables are harder to debug?
Global variables
What is a benefit of global variables?
What is a benefit of global variables?
Easy sharing of data across functions
What is a drawback of global variables?
What is a drawback of global variables?
Increased risk of errors
What is a benefit of local variables?
What is a benefit of local variables?
Efficient memory usage
How do you convert a global variable to a local one?
How do you convert a global variable to a local one?
Pass it as a parameter to functions
What is shadowing in the context of variables?
What is shadowing in the context of variables?
Local variable with same name as global
