ProgrammingHardTCS NQT · Infosys

int a[5] = {10, 20, 30, 40, 50}; int *p = a + 1, *q = a + 4; printf("%td %d", q - p, *(p + 2)); prints what?

  1. A. 3 40
  2. B. 4 50
  3. C. 3 30
  4. D. 2 40

Correct answer: A. 3 40

Subtracting two pointers into the same array gives the element distance, here 4 - 1 = 3. p + 2 points to a[3], which holds 40.

More C Programming questions

Exams that ask this topic