ProgrammingModerateAccenture · Cognizant pattern
What is printed?
What is printed?
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
printf("%d %d", *(*(a + 1) + 2), **a + 1);- A. 6 2
- B. 5 2
- C. 3 4
- D. 6 4
Correct answer: A. 6 2
*(a + 1) is row 1, and *(row1 + 2) is a[1][2] = 6. **a is a[0][0] = 1, and unary * binds tighter than +, so **a + 1 = 2. Reading it as **(a + 1) gives 4.
More C Programming questions
- 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));
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int x = 3, y = 5; int z = MAX(x++, y++); printf("%d %d %d", x, y, z);
- What is printed? c int i = 0, j = 1, k; k = i++ && j++ || ++j; printf("%d %d %d", i, j, k);
- What is printed (the code compiles)? c int x = (5, 10, 15); int y; y = 5, 10; printf("%d %d", x, y);
- With 4-byte int, what is printed? c int i = 5; sizet s = sizeof(i++); printf("%d %zu", i, s);