Difficulty: Easy
Correct Answer: cmp is a pointer to a function which returns void .
Explanation:
Introduction / Context:
This item checks your ability to recognize a function pointer type in C. The parentheses around *cmp are the telltale sign that cmp is not a function itself but a pointer to a function. Such pointers are used for callbacks, signal handlers, and dispatch tables.
Given Data / Assumptions:
Concept / Approach:
Reading with precedence: () applied to the declarator would make a function, but the parentheses force *cmp to bind before (), turning the whole into “pointer to function”. The type to the left, void, is the function's return type. There is no star on the return type, so it does not return a pointer; it returns nothing (void).
Step-by-Step Solution:
Verification / Alternative check:
Using a typedef: typedef void handler_t(void); handler_t *cmp; is equivalent and often clearer. Assign cmp = &some_handler; and invoke through (*cmp)(); to validate behavior in code.
Why Other Options Are Wrong:
Pointer to a void function type — Slightly awkward but closest in spirit; however, the best precise phrasing is “pointer to a function that returns void”.
Void type pointer function — Not meaningful; functions are not “pointer functions”.
Function that returns a void pointer — Would be void* f(); not this declaration.
Common Pitfalls:
Final Answer:
cmp is a pointer to a function which returns void .
Discussion & Comments