ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int a = 7;
int r = a % 3 + 2 * a / 7;
printf("%d", r);
  1. A. 4
  2. B. 3
  3. C. 9
  4. D. 1

Correct answer: B. 3

%, * and / share the same precedence level, evaluated left to right. a%3 = 1. 2*a = 14, then 14/7 = 2 (the * happens before the / since they're evaluated left-to-right at equal precedence). r = 1 + 2 = 3.

More C Programming questions

Exams that ask this topic