Difficulty: Medium
Correct Answer: p is an array of five pointers to functions, where each function returns an int.
Explanation:
Introduction / Context:
C declarations can look confusing when pointers, arrays and functions are combined. The declaration int (*p[5])(); is a classic interview question because it checks whether a candidate can correctly read complex declarator syntax and distinguish between arrays of pointers, pointers to arrays and pointers to functions. Understanding this declaration is important when working with callback tables or arrays of function pointers for dispatching behaviour based on indexes or states.
Given Data / Assumptions:
Concept / Approach:
To read complex C declarations, a common method is to apply the clockwise or spiral rule: start at the variable name, move outwards following operator precedence, and interpret parentheses carefully. In this declaration, p is inside brackets p[5], so p is first recognised as an array of five elements. The parentheses (*p[5]) bind the asterisk to the array elements, showing that each element is a pointer rather than a simple value. The trailing () indicates a function with unspecified parameters that returns an int. Putting this together, p is an array of five pointers to functions returning int.
Step-by-Step Solution:
Step 1: Focus on the identifier p inside the declaration int (*p[5])();
Step 2: Notice that p is followed by [5], so p is an array of five elements.
Step 3: Observe that the array notation is wrapped in parentheses with *, giving (*p[5]). This means each array element is a pointer, not a standalone value.
Step 4: Finally, see the () after (*p[5]). This indicates a function that returns int, and the pointer points to such a function.
Step 5: Combine all parts: p is an array (size 5) of pointers to functions that return int.
Verification / Alternative check:
If p is an array of function pointers, an example usage would be to assign functions to its elements like this: p[0] = someFunction; where someFunction is declared as int someFunction(); Then calling p[0]() invokes that function. This pattern is common in dispatch tables where different behaviours are selected by index. If p were a simple pointer to a single function or an array of int values, this kind of assignment and call pattern would not compile or behave as expected. The ability to store up to five different function addresses in p confirms that it is an array of pointers to functions returning int, as described in option B.
Why Other Options Are Wrong:
Option A ignores the [5] and treats p as a single pointer to a function, but the brackets clearly show p is an array of size five. Option C claims p is a pointer to a function returning an array, which is not what int (*p[5])(); expresses. Option D talks about a pointer to an array of functions, which is not valid in standard C because you cannot have an array of functions directly; functions are referred to via pointers. Option E misinterprets p as an array of int values, but the syntax with * and () shows that the elements are function pointers, not int values. Only option B correctly matches the declaration.
Common Pitfalls:
A frequent mistake is to read from left to right without considering how parentheses change precedence. Another pitfall is to think that functions themselves can be stored in arrays without using pointers. In C, arrays of function pointers are used instead. When facing any complex declaration, it helps to rewrite it more clearly or use typedefs, for example typedef int (*FuncPtr)(); FuncPtr p[5]; which clearly shows p is an array of function pointers. Practising this pattern makes reading declarations like int (*p[5])(); much easier.
Final Answer:
In this declaration, p is an array of five pointers to functions, and each of those functions returns an int.
Discussion & Comments