Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Level_Two_Exam

Total questions: 37

Worksheet time: 37mins

Name
Class
Date
1.

What is a variable in C++?

a)

A kind of loop

b)

A container that stores data

c)

A condition

d)

A function name

2.

Which of the following is a correct way to declare an integer variable in C++?

a)

int number;

b)

number int;

c)

int = number;

d)

number = int;

3.

What does an "if" statement do in C++?

a)

Repeats a block of code

b)

Runs code only if a condition is true

c)

Declares a variable

d)

Stops the program

4.

Which line shows a correct if condition in C++?

a)

if x == 5

b)

if (x == 5)

c)

if x = 5

d)

if x : 5

5.

Which loop is used when you know how many times you want to repeat something?

a)

if loop

b)

do loop

c)

for loop

d)

switch loop

6.

Which part of the for loop controls how many times the loop repeats?

a)

The condition in the middle

b)

The first part only

c)

The last part only

d)

None of the parts

7.

What is the difference between a while loop and a do-while loop?

a)

while runs at least once; do-while may not

b)

do-while runs at least once; while may not

c)

They are exactly the same

d)

do-while cannot have conditions

8.

Which loop checks the condition after the loop body?

a)

for loop

b)

while loop

c)

do-while loop

d)

if statement

9.

What is an array in C++?

a)

A single number

b)

A loop

c)

A group of variables of the same type

d)

A condition

10.

How do you access the first element of an array called marks?

a)

marks(0)

b)

marks.0

c)

marks[0]

d)

marks{0}

11.

Which of these is a correct variable name in C++?

a)

2value

b)

my value

c)

my_value

d)

int

12.

What will happen if you use a variable without declaring it?

a)

The program runs faster

b)

The program gives an error

c)

It prints 0

d)

It ignores the variable

13.

What is the output of this code? int x = 10; cout << x;

a)

0

b)

x

c)

10

d)

Nothing

14.

What type of variable stores decimal numbers in C++?

a)

int

b)

string

c)

float

d)

bool

15.

Which symbol means "equal to" in an if condition?

a)

=

b)

==

c)

!=

d)

<=

16.

Which symbol means "not equal to"?

a)

=

b)

<>

c)

!=

d)

!==

17.

What does this condition check? if (score > 50)

a)

If score is 50

b)

If score is less than 50

c)

If score is more than 50

d)

If score is equal to 50

18.

What does the following code do? for (int i = 0; i < 5; i++) cout << i << " ";

a)

Prints 1 2 3 4 5

b)

Prints 0 1 2 3 4

c)

Prints 0 1 2 3 4 5

d)

Prints nothing

19.

How many times does this loop run? for (int i = 0; i < 3; i++)

a)

2

b)

4

c)

3

d)

1

20.

What part of a for loop updates the counter?

a)

The first part

b)

The second part

c)

The third part

d)

The body

21.

When does a while loop stop repeating?

a)

When the user says stop

b)

When the condition becomes false

c)

After 10 times

d)

It never stops

22.

What is the output of this code? int i = 0; while (i < 3) { cout << i; i++; }

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Infinite loop

23.

When is the condition checked in a do-while loop?

a)

Before the loop starts

b)

After the loop ends

c)

After each loop run

d)

Never

24.

What is the index of the first element in a C++ array?

a)

0

b)

1

c)

-1

d)

10

25.

What will this print? int arr[3] = {10, 20, 30}; cout << arr[1];

a)

10

b)

20

c)

30

d)

Error

26.

How many elements are in this array? int nums[5];

a)

0

b)

4

c)

5

d)

6

27.

Which of these correctly accesses the last element in int a[4] = {1, 2, 3, 4};

a)

a[4]

b)

a[3]

c)

a[1]

d)

a[0]

28.

You can use a variable in C++ without declaring it first. (True/False)

a)

True

b)

False

29.

The 'if' statement is used to make decisions in a program. (True/False)

a)

True

b)

False

30.

In C++, the 'for' loop can be used to repeat code multiple times. (True/False)

a)

True

b)

False

31.

This line is correct: int 5number = 10; (True/False)

a)

True

b)

False

32.

An array can store more than one value of the same type. (True/False)

a)

True

b)

False

33.

In a 'while' loop, the condition is checked after the code runs. (True/False)

a)

True

b)

False

34.

The 'do-while' loop always runs the code at least once. (True/False)

a)

True

b)

False

35.

You can print values in C++ using cout. (True/False)

a)

True

b)

False

36.

The first element in an array is always at index 1. (True/False)

a)

True

b)

False

37.

This is a valid if condition: if (x = 5) (True/False)

a)

True

b)

False