Lesson 4.1.1.13
4.1.1.13 Local and global variables Quiz: AQA Computer Science, Unit 1
20 questions
In partnership with Revision Ninja
Lesson 4.1.1.13, Local and global variables: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
Which term describes a variable accessible only within its declaring subroutine?
- Pointer
- Constant
- Local variable
- Global variable
-
How does the scope of a local variable affect memory usage during program execution?
- Memory remains allocated
- Memory is doubled
- Memory becomes static
- Memory is released
-
Where is a global variable declared?
- Inside functions
- Outside subroutines
- Inside loops
- Local stack
-
What main risk is reduced by using local variables instead of global variables?
- Stack overflow
- Side effects
- Syntax errors
- Memory leaks
-
Two subroutines declare a local variable named count. How do these variables interact?
- Second overwrites first
- They are independent
- They share values
- Syntax error occurs
-
Which property primarily distinguishes a local variable from a global variable?
- Scope
- Memory size
- Identifier length
- Data type
-
What happens to a local variable when its subroutine finishes executing?
- It is destroyed
- Made global
- Moved to heap
- Saved to disk
-
What major issue can arise from updating global variables in multiple subroutines?
- Increased compilation time
- Difficult debugging
- Syntax errors
- Stack overflow
-
Why should intermediate calculations inside a subroutine use local variables?
- Makes variables global
- Speeds up compilation
- Frees memory automatically
- Prevents parameter passing
-
A function has a local variable x. A global x also exists. Which is accessed inside the function?
- The local variable
- Both variables
- Neither variable
- The global variable
-
What error occurs if a subroutine tries to access another subroutine's local variable?
- Scope error
- Stack overflow
- Type mismatch
- Syntax error
-
What key feature prevents local variables from colliding across different subroutines?
- Global registry
- Static linking
- Heap sorting
- Stack allocation
-
What is achieved by passing data via parameters rather than using global variables?
- Modular code design
- Automatic data compression
- Faster instruction cycles
- Reduced stack memory
-
A subroutine modifies a local variable sharing a name with a global variable. The global variable:
- Is overwritten
- Remains unchanged
- Resets to zero
- Is deleted
-
What is the most appropriate use of a global variable?
- Loop counter
- Temporary result
- Application-wide setting
- Subroutine parameter
-
What type of value might an uninitialised local variable hold?
- Constant value
- Unpredictable value
- Null reference
- Always zero
-
Which term describes a variable accessible only within the subroutine declaring it?
- Local scope
- Global scope
- Dynamic scope
- Universal scope
-
How should values be passed into a subroutine to avoid using global variables?
- As return values
- As global flags
- As constants
- As parameters
-
Where is memory allocated for local variables when a subroutine is called?
- On hard drive
- On call stack
- In heap memory
- In global memory
-
A local variable is initialised to 0 in a subroutine. What is its value at the start of a second call?
- 1
- 2
- 0
- Undefined
Related quizzes
- Data types Quiz · 4.1.1.1 · 20 questions
- Programming concepts: sequence, selection and iteration Quiz · 4.1.1.2 · 20 questions
- Arithmetic operations Quiz · 4.1.1.3 · 20 questions
- Relational and Boolean operations Quiz · 4.1.1.4 · 20 questions
- Constants and variables Quiz · 4.1.1.6 · 20 questions
- String-handling operations Quiz · 4.1.1.7 · 20 questions
- Random numbers and exception handling Quiz · 4.1.1.8 · 20 questions
- Subroutines Quiz · 4.1.1.10 · 20 questions
- Parameters and returning values Quiz · 4.1.1.11 · 20 questions
- Stack frames in subroutine calls Quiz · 4.1.1.15 · 20 questions