ProgrammingVery hardTCS NQT · Infosys · Product Company SDE
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int a[] = {5, 37, 35, 23, 22, 20, 33, 24, 36}; int *p = a + 4; printf("%d %d %d", *(p + 1) - *p, p[-1], (int)(&a[8] - p)); return 0; }
- A. -2 23 4
- B. -2 22 4
- C. -2 23 16
- D. 42 35 5
Correct answer: A. -2 23 4
p points at a[4]=22; *(p+1) is a[5]=20; p[-1] is a[3]=23; pointer subtraction counts elements, not bytes: 8−4 = 4.
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- Assume a 64-bit LP64 ABI. What is printed? c int a[4] = {1,2,3,4}; int (p)[4] = &a; printf("%d %d %zu", (p)[2], p, sizeof(p));
- 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]);