Difficulty: Easy
Correct Answer: void (*ptr)()
Explanation:
Introduction / Context:
This item checks whether you can construct a function pointer type for a procedure that takes no arguments and returns no value. In modern C, an explicit (void) parameter list indicates no parameters; older code sometimes uses empty parentheses, which historically meant an unspecified parameter list. Both styles appear in real code and documentation.
Given Data / Assumptions:
Concept / Approach:
The scheme for function pointers is return_type (*identifier)(parameters). We therefore place the pointer declarator around the identifier with parentheses, and supply the parameter list. Using an empty list () is commonly seen; the most explicit modern form is (void) to declare no parameters. Thus, void (*ptr)() is acceptable, and void (*ptr)(void) is even clearer where supported by your coding standard.
Step-by-Step Solution:
Verification / Alternative check:
With typedefs: typedef void proc_t(void); then proc_t *ptr; has the same meaning as void (*ptr)(void). Practical tests, like assigning ptr = &some_function; and invoking (*ptr)(); confirm correct behavior.
Why Other Options Are Wrong:
void *(ptr)*int; — Invalid grammar; mixes pointer declarators and parameters incorrectly.
void *(*ptr)() — Declares a function pointer returning void*, not void.
void *(*ptr)(*) — Not valid C syntax; parameter list cannot be a bare *.
Common Pitfalls:
Final Answer:
void (*ptr)()
Discussion & Comments