Font size
Worksheets12A and C version 1 Final Semester 1 Exam
Total questions: 20
Worksheet time: 25mins
What is the correct syntax to declare an integer variable in C++?
int num;
integer num;
var num;
num int;
What will the following code output? int x = 5, y = 10; cout << x + y;
10
15
50
Error
Which of the following loops executes at least once, regardless of the condition?
for loop
while loop
do-while loop
None of the above
What will the following code print? int a = 8; if (a % 2 == 0) cout << "Even"; else cout << "Odd";
Even
Odd
8
Error
What is the output of this code? for (int i = 0; i < 3; i++) cout << i << " ";
0 1 2
1 2 3
0 1 2 3
Error
Which operator is used for multiplication in C++?
/
*
%
#
What is the value of x after the following code executes? int x = 5; x += 10;
5
10
15
50
What does the following condition check? if (a > b)
Whether a is greater than or equal to b.
Whether a is equal to b.
Whether a is less than b.
Whether a is greater than b.
What type of variable should you use to store a decimal value?
int
float
bool
char
What is the output of this loop? int i = 0; while (i < 5) { cout << i; i++; }
01234
12345
1234
Error
The keyword used to define a variable in C++ is ______.
In an if-else statement, the (a) block is executed when the condition evaluates to false.
The operator used to calculate the remainder of a division is (a) .
A for loop includes three parts: initialization, (a) , and increment.
In C++, (a) is used to display output to the screen.
Write a program to check whether a given number is positive, negative, or zero using an if-else statement.
What is the difference between a while loop and a for loop in C++?
Write a program that uses a for loop to print the numbers from 1 to 10.
Explain the purpose of using the % operator in a real-world example.
Modify the following code to ensure it outputs "Even" or "Odd" based on the value of x: int x = 9; cout << x;
