ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
int a = 5, b, c;
b = a > 3 ? 10 : 20;
c = (b == 10) ? a + b : 0;
printf("%d %d %d", a, b, c);- A. 5 20 0
- B. 5 10 0
- C. 5 10 10
- D. 5 10 15
Correct answer: D. 5 10 15
a > 3 is true, so b = 10; then b == 10 is true, so c = 5 + 10 = 15. The conditional operator evaluates only the selected branch.
More C Programming questions
- What is printed? c struct A { char c; int i; char d; }; struct B { int i; double d; }; struct C { char c; double d; char e; }; printf("%zu…
- What is printed? c char s = "hello"; printf("%c %c %c", s[1], 4[s], ("abc" + 2));
- What is printed? c int x = 10; int p = &x; int q = &p; q = 20; p += 5; printf("%d", x);
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int i = 3; int r = MAX(i++, 2); printf("%d %d", r, i);
- What is printed? c unsigned int i; int count = 0; for (i = 3; i >= 0; i--) { if (++count == 5) break; } printf("%d %u", count, i); /…
- What is printed? c printf("%d %d %d %d", -17 / 5, -17 % 5, 17 / -5, 17 % -5);