ProgrammingVery hardProduct company OA

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

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

Correct answer: A. 3 1 8

p is a pointer to the whole array of 4 ints (type int(*)[4]). (*p)[2] dereferences the array then indexes, giving a[2]=3. **p dereferences twice: *p is the array (decays to &a[0]), *(*p) is a[0]=1. sizeof(p) is a pointer size, 8 on LP64, not the array size.

More C Programming questions

Exams that ask this topic