Which option gives the correct interpretation of the following declaration in…
2018
Which option gives the correct interpretation of the following declaration in C++?
int(*p[5])();
- A.
p is a pointer to function
- B.
p is an array of pointers to function
- C.
p is a pointer to such function which return type is array
- D.
p is a pointer to an array of functions
Attempted by 105 students.
Show answer & explanation
Correct answer: B
To parse the declaration int(*p[5])(), start with the identifier p. The brackets [5] indicate that p is an array of 5 elements. The parentheses around *p[5] override the default precedence, meaning each element of the array is a pointer. Finally, the trailing () indicates that these pointers point to functions returning an integer. Thus, p is an array of 5 pointers to functions that return int.