Font size
Worksheets12A and C version 2 Final Semester 1 Exam
Total questions: 20
Worksheet time: 23mins
Which symbol is used to end a statement in C++?
:
;
,
.
What will the following code output? int a = 3, b = 7; cout << a * b;
10
21
37
Error
Which loop checks the condition before executing the body?
do-while loop
for loop
infinite loop
None of the above
What will the following code print? int n = 15; if (n % 5 == 0) cout << "Divisible"; else cout << "Not Divisible";
Divisible
Not Divisible
Error
15
How many times will this loop execute? for (int i = 1; i <= 5; i++) cout << i;
4
5
Infinite
Error
What is the correct operator to compare two values for equality?
=
==
!=
=>
What is the value of y after this code executes? int y = 8; y -= 3;
3
5
8
11
What will cout print in the following code? int a = 2, b = 3; cout << a + b * 2;
10
8
12
Error
Which data type is used to store a single character?
string
int
char
bool
What will the following code output? int i = 1; while (i <= 3) { cout << i << " "; i++; }
1 2 3
0 1 2
1 2 3 4
Error
The (a) operator is used to compare two values for equality.
In C++, a variable of type (a) can store either true or false.
The loop that always executes at least once is the (a) loop.
The cin object in C++ is used to take (a) from the user.
To include a library in C++, the #include directive is used at the (a) of the program.
Write a program to determine whether a given number is even or odd using the % operator.
What is the difference between the == operator and the = operator in C++? Explain with examples.
Write a program that uses a while loop to print numbers from 1 to 5.
Explain the role of the for loop in C++.
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;
