Which term describes the parts of a program in which a variable can be seen and used?
Scope
What is meant by a global variable?
A variable that can be accessed anywhere in a program
Which term describes a variable that only exists while the subprogram it is created in is executing?
Local variable
What is meant by a parameter?
A value that is passed into a subprogram when it is called
Which term describes a variable that is declared in the main program and can be used inside any subprogram?
Global variable
What is meant by scope?
The parts of a program where a variable is recognised
A variable is declared inside a subprogram. Which statement about this variable is true?
It can be used only while that subprogram is executing
What does a subprogram need in order to change the value of a global variable?
The global keyword before the variable name
A local variable in one subprogram has the same name as a local variable in another subprogram. What happens?
Each subprogram uses its own separate variable
Why is it generally recommended to use local variables wherever possible?
They keep a subprogram self-contained so it can be reused
A constant is declared in the main program and used inside a subprogram. What is true?
It can be read in the subprogram but not changed
A program has a global variable called score. A subprogram that wants to update score uses a local variable with the same name instead. What is the result?
The global score keeps its original value
A subprogram needs to read the value of a global variable but does not need to change it. What is needed?
Nothing extra is needed to read the variable
What does this program print?
3 then 10
When is it most appropriate to use a global variable rather than a local one?
When several subprograms need to share and update the same value
Which one of these is a global variable in this program?
score
We use cookies to enhance your experience. You can manage your preferences or learn more in our Cookie Policy.