What is the result of 10 / 3 in C++ (both operands are integers)?
A
3.33 B
3 C
3.0 D
Error
Analysis & Theory
Integer division in C++ truncates the decimal part. 10 / 3 returns 3.
Which header file is needed to use mathematical functions like sqrt() and pow() in C++?
A
<math.h> B
<cmath> C
<math> D
<maths.h>
Analysis & Theory
<cmath> is the C++ standard header for mathematical functions.
What is the output of pow(2, 3) in C++?
A
6 B
8 C
9 D
2
Analysis & Theory
pow(2, 3) computes 2 raised to the power 3, which is 8.
Which function returns the square root of a number in C++?
A
sqrt() B
sqr() C
power() D
root()
Analysis & Theory
sqrt() is used to compute the square root of a number.
What is the result of abs(-9) in C++?
A
-9 B
9 C
0 D
Error
Analysis & Theory
abs() returns the absolute value, so abs(-9) is 9.
Which function is used to compute the remainder in C++?
A
% B
mod() C
remainder() D
divmod()
Analysis & Theory
The % operator gives the remainder when dividing two integers.
What does the ceil(4.2) function return in C++?
A
4 B
5 C
4.0 D
4.5
Analysis & Theory
ceil() returns the smallest integer not less than the number, so ceil(4.2) is 5.
Which of the following expressions results in a float in C++?
A
5 / 2 B
5.0 / 2 C
5 / 2.0 D
Both B and C
Analysis & Theory
If either operand is float/double, the result is a floating-point division.
Which function rounds a number to the nearest integer in C++?
A
round() B
floor() C
int() D
modf()
Analysis & Theory
round() returns the nearest integer. floor() always rounds down.
Which function returns the largest integer not greater than the given number?
A
ceil() B
floor() C
round() D
trunc()
Analysis & Theory
floor() returns the largest integer less than or equal to the input.