ProgrammingModerateHCL · Tech Mahindra pattern
What is printed?
What is printed?
int n = 5;
while (n-- > 2)
printf("%d", n);
printf(" %d", n);- A. 432 1
- B. 543 2
- C. 43 1
- D. 432 2
Correct answer: A. 432 1
Each test compares the old n, then decrements: 5 > 2 (prints 4), 4 > 2 (prints 3), 3 > 2 (prints 2), 2 > 2 fails but still decrements n to 1. So 432, then 1.
More C Programming questions
- Given int x = 1, y = 2; const int p = &x; int const q = &x; which pair of statements both fail to compile?
- What is printed? c enum { A, B = 5, C, D = 2, E }; printf("%d %d %d", A, C, E);
- With 4-byte int, what is printed? c int a[] = {1, 2, 3}; char p = (char )a; p += 4; printf("%d", (int )p);
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d", ((a + 1) + 2), a + 1);
- What is printed? c int x = 3; if (x = 0) printf("A%d", x); else printf("B%d", x);
- What is printed? c int add(int a, int b) { return a + b; } ... int (fp)(int, int) = add; printf("%d", (fp)(2, 3) + fp(4, 5));