wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

12A and C version 2 Final Semester 1 Exam

Total questions: 20

Worksheet time: 23mins

Name
Class
Date
1.

Which symbol is used to end a statement in C++?

a)

:

b)

;

c)

,

d)

.

2.

What will the following code output? int a = 3, b = 7; cout << a * b;

a)

10

b)

21

c)

37

d)

Error

3.

Which loop checks the condition before executing the body?

a)

do-while loop

b)

for loop

c)

infinite loop

d)

None of the above

4.

What will the following code print? int n = 15; if (n % 5 == 0) cout << "Divisible"; else cout << "Not Divisible";

a)

Divisible

b)

Not Divisible

c)

Error

d)

15

5.

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

a)

4

b)

5

c)

Infinite

d)

Error

6.

What is the correct operator to compare two values for equality?

a)

=

b)

==

c)

!=

d)

=>

7.

What is the value of y after this code executes? int y = 8; y -= 3;

a)

3

b)

5

c)

8

d)

11

8.

What will cout print in the following code? int a = 2, b = 3; cout << a + b * 2;

a)

10

b)

8

c)

12

d)

Error

9.

Which data type is used to store a single character?

a)

string

b)

int

c)

char

d)

bool

10.

What will the following code output? int i = 1; while (i <= 3) { cout << i << " "; i++; }

a)

1 2 3

b)

0 1 2

c)

1 2 3 4

d)

Error

11.

The (a)   operator is used to compare two values for equality.

12.

In C++, a variable of type (a)   can store either true or false.

13.

The loop that always executes at least once is the (a)   loop.

14.

The cin object in C++ is used to take (a)   from the user.

15.

To include a library in C++, the #include directive is used at the (a)   of the program.

16.

Write a program to determine whether a given number is even or odd using the % operator.

4 lines
17.

What is the difference between the == operator and the = operator in C++? Explain with examples.

4 lines
18.

Write a program that uses a while loop to print numbers from 1 to 5.

4 lines
19.

Explain the role of the for loop in C++.

4 lines
20.

Modify the following code to calculate and display the sum of two numbers entered by the user: int a, b; cout << "Enter two numbers: "; cin >> a >> b;

4 lines