ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 2, b = 3, c = 4;
int r = a + b * c - a / b;
printf("%d", r);- A. 12
- B. 9
- C. 6
- D. 14
Correct answer: D. 14
Precedence: * and / bind before +/-, and * / have equal precedence evaluated left-to-right where relevant (here they're separate terms): b*c=12, a/b=2/3=0 (integer division). r = 2 + 12 - 0 = 14.
More C Programming questions
- What is printed? c int a = 5; int r = a > 3 ? 10 : 20 + 5; printf("%d", r);
- What is printed? c int a = 4; int r = ~a + 1 == -a; printf("%d", r);
- What is printed? c int a = 3, b = 4, c = 5; int r = a + b == c ? 1 : 0; printf("%d", r);
- What is printed? c int a = 5; int b = a++, c = ++a; printf("%d %d %d", a, b, c);
- What is printed? c int x = 2, y = 3, z = 4; int r = x + y == z || x y == z + 2; printf("%d", r);
- What is printed? c int a = 7; int r = a % 3 + 2 a / 7; printf("%d", r);