What is the output of printf("%d", 5 / 2); in C?
-
A
2.5
-
B
2
Correct answer
-
C
3
-
D
0
10 views
Explanation
Integer division truncates the decimal part. 5 / 2 = 2, not 2.5. To get 2.5, at least one operand must be a float. This is a common source of bugs.
Reference
Asked in: Matric,FBISE
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ