ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
int i = 10, c = 0;
do {
c++;
i++;
} while (i < 5);
printf("%d %d", i, c);- A. 10 0
- B. 11 0
- C. 11 1
- D. 6 1
Correct answer: C. 11 1
A do-while checks its condition after the body, so the body runs once even though 10 < 5 is false from the start. A while loop with the same condition would not run at all.
More C Programming questions
- What is printed? c int i, j, s = 0; for (i = 0, j = 10; i < j; i += 2, j--) s += j - i; printf("%d %d %d", i, j, s);
- What is printed? c unsigned int u = -16; / 32-bit unsigned int / printf("%d %u %d", 1 << 4, u >> 28, -16 / 4);
- What is printed? c int a = 5, b, c; b = a > 3 ? 10 : 20; c = (b == 10) ? a + b : 0; printf("%d %d %d", a, b, c);
- 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);