Difficulty: Medium
Correct Answer: pf is a pointer to a function which return int
Explanation:
Introduction / Context:
This question tests mastery of C declarator syntax for function pointers. Reading complex declarations correctly is essential when using callbacks, library hooks, signal handlers, and tables of operations. The declaration style can look cryptic at first, but a small set of rules lets you decode it reliably.
Given Data / Assumptions:
Concept / Approach:
Use the clockwise spiral rule or a simple precedence rule: identifiers bind first to the closest parentheses, postfix operators like () and [] have higher precedence than unary *. In int (*pf)(); the inner parentheses force *pf to bind before (), producing a pointer-to-function rather than a function returning a pointer. The base type to the left is int, meaning the function's return type is int.
Step-by-Step Solution:
Verification / Alternative check:
Compare with int *pf(); which declares a function named pf that returns int* (function returning pointer). The absence or presence of parentheses around *pf is decisive. You can also create a typedef: typedef int func_t(); then func_t *pf; makes the same meaning obvious.
Why Other Options Are Wrong:
pf is a pointer to function. This is incomplete because it omits the return type, which is int; the precise statement includes “return int”.
pf is a function pointer. Too generic. While true in spirit, the best answer must state the return type.
pf is a function of pointer variable. Nonsensical phrasing; the syntax does not declare a function of a pointer.
Common Pitfalls:
Final Answer:
pf is a pointer to a function which return int
Discussion & Comments