wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

12A and C version 1 Final Semester 1 Exam

Total questions: 20

Worksheet time: 25mins

Name
Class
Date
1.

What is the correct syntax to declare an integer variable in C++?

a)

int num;

b)

integer num;

c)

var num;

d)

num int;

2.

What will the following code output? int x = 5, y = 10; cout << x + y;

a)

10

b)

15

c)

50

d)

Error

3.

Which of the following loops executes at least once, regardless of the condition?

a)

for loop

b)

while loop

c)

do-while loop

d)

None of the above

4.

What will the following code print? int a = 8; if (a % 2 == 0) cout << "Even"; else cout << "Odd";

a)

Even

b)

Odd

c)

8

d)

Error

5.

What is the output of this code? for (int i = 0; i < 3; i++) cout << i << " ";

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Error

6.

Which operator is used for multiplication in C++?

a)

/

b)

*

c)

%

d)

#

7.

What is the value of x after the following code executes? int x = 5; x += 10;

a)

5

b)

10

c)

15

d)

50

8.

What does the following condition check? if (a > b)

a)

Whether a is greater than or equal to b.

b)

Whether a is equal to b.

c)

Whether a is less than b.

d)

Whether a is greater than b.

9.

What type of variable should you use to store a decimal value?

a)

int

b)

float

c)

bool

d)

char

10.

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

a)

01234

b)

12345

c)

1234

d)

Error

11.

The keyword used to define a variable in C++ is ______.

4 lines
12.

In an if-else statement, the (a)   block is executed when the condition evaluates to false.

13.

The operator used to calculate the remainder of a division is (a)   .

14.

A for loop includes three parts: initialization, (a)   , and increment.

15.

In C++, (a)   is used to display output to the screen.

16.

Write a program to check whether a given number is positive, negative, or zero using an if-else statement.

4 lines
17.

What is the difference between a while loop and a for loop in C++?

4 lines
18.

Write a program that uses a for loop to print the numbers from 1 to 10.

4 lines
19.

Explain the purpose of using the % operator in a real-world example.

4 lines
20.

Modify the following code to ensure it outputs "Even" or "Odd" based on the value of x: int x = 9; cout << x;

4 lines