wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Variable Scope

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

What is the scope of a global variable?

a)

The entire program

b)

The sub-program where it has been declared

c)

Only within the function where it has been declared

d)

Only within the class where it has been declared

2.

Where is the value of a global variable accessible?

a)

Only within the function where it has been declared

b)

Only within the class where it has been declared

c)

Throughout the entire program

d)

Only within the sub-program where it has been declared

3.

What is the impact of errors in code on global variables?

a)

No impact

b)

The value of the global variable is lost

c)

The value of the global variable can be accidentally changed

d)

The global variable becomes inaccessible

4.

Why can global variables be a major problem in real commercial programs?

a)

They consume excessive system resources

b)

They can cause errors in code

c)

There may be hundreds or thousands of variables in use

d)

They are difficult to declare and use

5.

What is the scope of a local variable?

a)

The entire program

b)

The sub-program where it has been declared

c)

Only within the function where it has been declared

d)

Only within the class where it has been declared

6.

Where are the values of local variables held?

a)

In the main memory

b)

In the cache memory

c)

In the hard disk

d)

In the RAM

7.

What happens to a local variable after the execution of its sub-program?

a)

It is retained in RAM

b)

It is lost

c)

It becomes a global variable

d)

It is moved to the cache memory

8.

What is the advantage of using local variables?

a)

They consume less system resources

b)

They can be accessed from any part of the program

c)

They are easier to declare and use

d)

They have a wider scope

9.

How many variables can be declared in a real commercial program?

a)

None

b)

A few

c)

Hundreds or thousands

d)

Unlimited

10.

What is the main disadvantage of global variables?

a)

They are difficult to declare and use

b)

They consume excessive system resources

c)

They can cause errors in code

d)

They have a limited scope

11.

Where are global variables stored in memory?

a)

In the main memory

b)

In the cache memory

c)

In the hard disk

d)

In the RAM