ProgrammingHardTCS NQT · Infosys

struct P { int x, y; } arr[4]; struct P *p = arr; p += 2; What is p - arr?

  1. A. 2
  2. B. 4
  3. C. 8
  4. D. 1

Correct answer: A. 2

p += 2 moves two struct elements, not two ints, so p - arr is 2. Pointer arithmetic counts whole objects of the pointed-to type.

More C Programming questions

Exams that ask this topic