Q. Predict the data type of the following mathematical operation?
2 * 9 + 3 / 2 . 0
2 * 9 + 3 / 2 . 0
β
Correct Answer: (B)
double
Explanation:
The given mathematical expression is:
2 * 9 + 3 / 2.0
Let's break it down step by step:
Identify the Data Types:
- 2 and 9 are integers (int).
- 3 / 2.0 contains 2.0, which is a double (since any number with a decimal point is treated as a double in C by default).
- Because of implicit type conversion, 3 (int) is promoted to 3.0 (double) before division.
Perform Operations:
- 2 * 9 = 18 (int)
- 3 / 2.0 = 1.5 (double)
- 18 + 1.5 = 19.5 (double)
Final Data Type:
- Since one operand in 3 / 2.0 was a double, the result of the entire expression follows type promotion rules and becomes double.
Conclusion:
The final result is of double type. Hence, the correct answer is (B) double.