wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ Operators and Control Flow Quiz

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

Which operator is used to assign a value to a variable?

a)

==

b)

=

c)

!=

d)

>=

2.

What will be the output of the code: int x = 10, y = 3; cout 3 && 2 = 10);?

a)

true

b)

false

c)

1

d)

0

3.

Which operator has the highest precedence?

a)

+

b)

*

c)

=

d)

==

4.

What does != mean in C++?

a)

Assign value

b)

Equal to

c)

Not equal to

d)

Greater than

5.

Which statement executes code only when a condition is true?

a)

for

b)

while

c)

if

d)

switch

6.

What happens if break is missing in a switch case?

a)

Program stops

b)

Error occurs

c)

Next case executes

d)

Nothing happens

7.

When does the else block execute?

a)

When condition is true

b)

When condition is false

c)

Always

d)

Never

8.

Which loop checks the condition before execution?

a)

do-while

b)

for

c)

while

d)

Both for and while

9.

Which loop executes at least once even if the condition is false?

a)

for

b)

while

c)

do-while

d)

switch

10.

What is the output? for (int i = 1; i <= 3; i++) cout << i;

a)

123

b)

012

c)

321

d)

111

11.

How many times will this loop execute? int i = 0; while (i < 5) { i++; }

a)

4

b)

5

c)

6

d)

Infinite

12.

Which keyword skips the current loop iteration?

a)

stop

b)

exit

c)

break

d)

continue

13.

Which loop is best when the number of repetitions is known?

a)

while

b)

do-while

c)

for

d)

switch

14.

What happens when break is used inside a loop?

a)

Skips one iteration

b)

Restarts the loop

c)

Exits the loop immediately

d)

Ends the program

15.

What is the result of the expression: 5 + 3 * 2?

a)

10

b)

16

c)

11

d)

8

16.

Which keyword is used to define a function in C++?

a)

method

b)

void

c)

function

d)

def

17.

What will be the output of the following code: int a = 5; if (a > 3) cout << "Greater";

a)

Greater

b)

No output

c)

3

d)

5

18.

What is the purpose of the 'return' statement in a function?

a)

To define a function

b)

To return a value from the function

c)

To exit the program

d)

To create a loop

19.

What will be the output of the following code: int a = 10; if (a < 5) cout << "Less"; else cout << "More";

a)

Error

b)

No output

c)

More

d)

Less

20.

Which operator is used to compare two values for equality?

a)

===

b)

==

c)

=

d)

!=

21.

What is the output of the following code: int x = 5; if (x == 5) cout << "Equal"; else cout << "Not Equal";

a)

Equal

b)

Error

c)

No output

d)

Not Equal

22.

Which keyword is used to create a loop that iterates over a range of values?

a)

for

b)

loop

c)

foreach

d)

iterate

23.

What will be the output of the following code: int a = 2, b = 3; cout << (a + b) * 2;

a)

6

b)

8

c)

10

d)

12