Practice mode C Language

What is printed by this C code: int x = 2 + 3 * 4 % 5; printf(“%d”, x);?

Correct answer A. 4

Explanation

*, / and % share the same precedence, higher than +, and they associate left to right. So 3 * 4 is evaluated first (12), then 12 % 5 gives 2, and finally 2 + 2 gives 4. The answer 0 comes from wrongly computing (2 + 3 * 4) % 5, and 14 ignores the % entirely. Learning precedence groups, not individual operators, avoids such mistakes.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.