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));- A. 3 1 8
- B. 3 1 4
- C. 3 1 16
- 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
- What is printed? c int a[] = {1,2,3,4,5}; int p = a + 3; int q = a; printf("%d %d %d", p - q, p-- , p);
- What is printed? c int a[5] = {1,2,3,4,5}; int p = &a[2]; printf("%d %d %d", p[-1], p[2], 2[p]);
- Assume a 64-bit LP64 ABI. What is printed? c int a[10]; int p = a + 2; int q = a + 7; printf("%ld %ld", (long)(q - p), (long)((char)q…
- What is printed, assuming no undefined-behavior crash occurs on this platform? c int a[3] = {1,2,3}; int b[3] = {4,5,6}; int p = a + 3…
- What is printed? c int x = 5; void vp = &x; int ip = (int)vp; (ip)++; printf("%d", (int)vp);
- What is printed? c int a[5] = {1,2,3,4,5}; int p = a; for (p = a; p < a + 5; p++) { if (p == a + 2) continue; printf("%d", p); }