What is the output of the below given statement in C?
printf("%d", 9+21/5-2*4);The correct answer is 5.
- Division (/) and multiplication (*) have same order of precedence and associativity is from left to right
- Addition (+) and subtraction (-) have the same order of precedence and associativity is from left to right
- / or * has a higher order of precedence then + or –
- %d → conversion specifier for an integer
Therefore: (9 + (21 ÷ 5)) - (2 × 4)) → considering the associativity of operators
⇒21 ÷ 5 corresponds to ⌊21 ÷ 5 ⌋ = 4
⇒((9 + 4) - 8) = 5

