ProgrammingHardIBM · Deloitte pattern

Assume a 64-bit LP64 ABI. Which declaration makes p an array of 5 pointers to int, and which makes q a pointer to an array of 5 ints?

  1. A. int (*p)[5]; and int *q[5];
  2. B. int p[5]*; and int q*[5];
  3. C. int *p[5]; and int *q[5];
  4. D. int *p[5]; and int (*q)[5];

Correct answer: D. int *p[5]; and int (*q)[5];

Array subscript [] binds tighter than the unary * in a declaration, so int *p[5] is parsed as (* of each of) p[5] — an array of 5 pointers. Parentheses override that: int (*q)[5] groups the * with q first, making q a single pointer to an array of 5 ints.

More C Programming questions

Exams that ask this topic