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[] = {36, 21, 21, 23, 21, 8, 7, 32, 3}; int *p = a + 5; printf("%d %d %d", *(p + 1) - *p, p[-1], (int)(&a[8] - p)); return 0; }
- A. 1 21 3
- B. -1 21 3
- C. -1 8 3
- D. -1 21 12
Correct answer: B. -1 21 3
p points at a[5]=8; *(p+1) is a[6]=7; p[-1] is a[4]=21; pointer subtraction counts elements, not bytes: 8−5 = 3.
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…
- 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…