ProgrammingHardProduct-company MCQ pattern

With 4-byte int, consider int (*p)[5]; Which is correct?

  1. A. p is an array of 5 pointers to int, and p + 1 moves 4 bytes ahead
  2. B. p is an array of 5 pointers to int, and p + 1 moves 8 bytes ahead
  3. C. p is a pointer to an array of 5 ints, and p + 1 moves 20 bytes ahead
  4. D. p is a pointer to an array of 5 ints, and p + 1 moves 4 bytes ahead

Correct answer: C. p is a pointer to an array of 5 ints, and p + 1 moves 20 bytes ahead

The parentheses bind * to p first, so p is a pointer, and what it points to is int[5]. Pointer arithmetic steps by the size of the pointee: 5 × 4 = 20 bytes. int *p[5] (no parentheses) would be an array of 5 pointers.

More C Programming questions

Exams that ask this topic