wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ QUIZ

Total questions: 14

Worksheet time: 5mins

Name
Class
Date
1.

Who is the creator of C++?

a)

Dennis Ritchie

b)

James Gosling

c)

Bjarne Stroustrup

d)

Guido van Rossum

2.

In which year was C++ created?

a)

1980✅

b)

1983

c)

1972

d)

1991

3.

Which of the following is a correct C++ comment?

a)

This is a comment

b)

<-- This is a comment -->

c)

# This is a comment

d)

/* This is a comment */

4.

What is the correct syntax to print "Hello, World!" in C++?

a)

print("Hello, World!");

b)

Console.WriteLine("Hello, World!");

c)

cout << "Hello, World!";

d)

printf("Hello, World!");

5.

What will be the output of this if-else statement?
int x = 10;
if (x > 10)
cout << "Greater";
else
cout << "Smaller";

a)

Smaller

b)

Greater

c)

Error

d)

No output

6.

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

cout << i << " ";

}

a)

Infinite

b)

6 times

c)

4 times

d)

5 times

7.

What is the output of this loop?
int i = 1;

while (i < 4) {

cout << i << " ";

i++;

}

a)

1 2 3

b)

0 1 2

c)

1 2 3 4

d)

Infinite loop

8.

Which of the following is NOT a C++ loop?

a)

while

b)

for

c)

do-while

d)

repeat

9.

How can you terminate a loop in C++?

a)

continue;

b)

break;

c)

exit;

d)

terminate;

10.

What is the output of this code?

int x = 5;

if (x == 5) {

cout << "Equal";

} else {

cout << "Not Equal";

}

a)

No Output

b)

Error

c)

Not Equal

d)

Equal

11.

What is the purpose of the else statement in C++?

a)

Skips the next statement

b)

Loops infinitely

c)

Runs when the if condition is true

d)

Runs when the if condition is false

12.

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

a)

for loop

b)

while loop

c)

infinite loop

d)

do-while loop

13.

What does the continue statement do inside a loop?

a)

Ends the loop execution

b)

Skips the rest of the code in the current iteration and moves to the next iteration

c)

Exits the program

d)

Restarts the loop from the beginning

14.

What is the correct syntax for an if-else statement in C++?

a)

if {x == 5} then {cout << "Yes";} else {cout << "No";}

b)

if x == 5

cout << "Yes";

else

cout << "No";

c)

if (x == 5)

cout << "Yes";

else

cout << "No";

d)

if x = 5 { cout << "Yes"; } else { cout << "No"; }