ProgrammingHard

int *arr = malloc(5 * sizeof *arr); for (int i = 0; i < 5; i++) arr[i] = i * i; int *q = arr + 2; printf("%d", q[1]); What is printed?

  1. A. 9
  2. B. 4
  3. C. 16
  4. D. 1

Correct answer: A. 9

q = arr + 2 points at arr[2], so q[1] is *(q + 1) = arr[3] = 3 * 3 = 9. 4 reads q[1] as arr[2], forgetting the offset adds to q, and 16 jumps one element too far to arr[4].

More C Programming questions

Exams that ask this topic