ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
/* LP64: 4-byte int, 8-byte pointers */
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
int (*p)[3] = a;
printf("%d %d %zu %zu", p[1][2], **(p + 1), sizeof(*p), sizeof(p));- A. 6 4 12 8
- B. 6 2 12 8
- C. 6 4 4 8
- D. 6 4 12 12
Correct answer: A. 6 4 12 8
p is a pointer to an array of 3 ints, so p + 1 skips a whole row. p[1][2] is a[1][2] = 6, and **(p + 1) is the first element of row 1, 4 (2 would come from treating p as a plain int pointer). *p is an entire row: sizeof is 3 × 4 = 12. p itself is just a pointer: 8 bytes.
More C Programming questions
- What is printed? c int i, c = 0; for (i = 0; i < 6; i++) if (i % 2 == 0 || ++c > 1) c += 10; printf("%d %d", i, c);
- What is printed? c / 16-bit unsigned short, 32-bit int and unsigned / unsigned short a = 3, b = 5; printf("%d %u %d", a - b, 3u - 5u…
- What is printed? c #define ABS(x) x < 0 ? -x : x printf("%d %d", ABS(2 - 5), ABS(-4) 2);
- What is printed? c const char s = "mississippi"; printf("%td %td %td", strchr(s, 's') - s, strrchr(s, 's') - s, strstr(s, "ssip") - s);
- What is printed? c / 4-byte int / struct V { int a[3]; }; void f(struct V v) { v.a[0] = 9; } void g(int a[3]) { a[0] = 9; } int main(void)…
- What is printed? c int n = 10, c = 0; int k = (n + 3) / 4; switch (n % 4) { case 0: do { c++; case 3: c++; case 2: c++; case 1: c++; }…