ProgrammingHardTCS NQT · Infosys

int a[] = {2, 4, 6, 8}; int *p = a + 3, *q = a; What does printf("%td", p - q) print?

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

Correct answer: C. 3

Subtracting pointers into the same array gives the number of elements between them. p points to a[3] and q to a[0], so the difference is 3.

More C Programming questions

Exams that ask this topic