ProgrammingHardHCL · Tech Mahindra pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a[5] = {10, 20, 30, 40, 50};
int *p = a + 4;
int *q = a;
printf("%ld %d %d", p - q, *(p - 2), q[3]);
  1. A. 4 20 40
  2. B. 4 30 30
  3. C. 4 30 40
  4. D. 16 30 40

Correct answer: C. 4 30 40

Pointer subtraction p - q gives the number of ELEMENTS between them (not bytes): 4. p - 2 points two ints before p (index 4-2=2), so *(p-2) = a[2] = 30. q[3] is a[3] = 40.

More C Programming questions

Exams that ask this topic