ProgrammingHardHCL · Tech Mahindra pattern

What is printed? Assume a 64-bit LP64 ABI (4-byte int).

What is printed? Assume a 64-bit LP64 ABI (4-byte int).
int a[3][2] = {{1,2},{3,4},{5,6}};
int (*p)[2] = a;
p = p + 2;
printf("%ld %d", (long)((char*)p - (char*)a), p[0][1]);
  1. A. 16 4
  2. B. 8 6
  3. C. 16 6
  4. D. 32 6

Correct answer: C. 16 6

Each row of a is 2 ints = 8 bytes, so p (a pointer-to-row) advancing by 2 rows moves 16 bytes; the byte-cast difference confirms 16. p now aliases row a[2], so p[0][1] = a[2][1] = 6.

More C Programming questions

Exams that ask this topic