ProgrammingHardCompetitive coding (CP) · C internals

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { int arr[5] = {1, 2, 3, 4, 5}; int *p = &arr[0]; for (int i = 0; i < 5; i++) { printf("%d ", *(p + i)); } return 0; }

  1. A. 5 4 3 2 1
  2. B. 0 1 2 3 4
  3. C. 1 2 3 4 5
  4. D. 2 3 4 5 6

Correct answer: C. 1 2 3 4 5

p points at arr[0]; *(p+i) for i=0..4 walks through the array in order, printing 1 2 3 4 5.

More C Programming questions

Exams that ask this topic