ProgrammingHardWipro · Cognizant pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
int a[2][2] = {{1, 2}, {3, 4}};
int *p = a[0];
int *q = a[1];
printf("%ld", q - p);
  1. A. 8
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

a[0] and a[1] decay to int* pointing at the first element of each row. q - p is pointer subtraction measured in elements (int units): row 1 starts 2 ints after row 0 starts (since each row has 2 ints), so the difference is 2, not the byte distance 8.

More C Programming questions

Exams that ask this topic