NEW
Font size
WorksheetsVariable Scope
Total questions: 11
Worksheet time: 6mins
What is the scope of a global variable?
The entire program
The sub-program where it has been declared
Only within the function where it has been declared
Only within the class where it has been declared
Where is the value of a global variable accessible?
Only within the function where it has been declared
Only within the class where it has been declared
Throughout the entire program
Only within the sub-program where it has been declared
What is the impact of errors in code on global variables?
No impact
The value of the global variable is lost
The value of the global variable can be accidentally changed
The global variable becomes inaccessible
Why can global variables be a major problem in real commercial programs?
They consume excessive system resources
They can cause errors in code
There may be hundreds or thousands of variables in use
They are difficult to declare and use
What is the scope of a local variable?
The entire program
The sub-program where it has been declared
Only within the function where it has been declared
Only within the class where it has been declared
Where are the values of local variables held?
In the main memory
In the cache memory
In the hard disk
In the RAM
What happens to a local variable after the execution of its sub-program?
It is retained in RAM
It is lost
It becomes a global variable
It is moved to the cache memory
What is the advantage of using local variables?
They consume less system resources
They can be accessed from any part of the program
They are easier to declare and use
They have a wider scope
How many variables can be declared in a real commercial program?
None
A few
Hundreds or thousands
Unlimited
What is the main disadvantage of global variables?
They are difficult to declare and use
They consume excessive system resources
They can cause errors in code
They have a limited scope
Where are global variables stored in memory?
In the main memory
In the cache memory
In the hard disk
In the RAM
