I finally figured out the syntax for declaring pointers to functions
C Interview Questions and Answers
(Continued from previous question...)
I finally figured out the syntax for declaring pointers to functions
Q: I finally figured out the syntax for declaring pointers to functions, but now how do I initialize one?
A: Use something like
extern int func();
int (*fp)() = func;
When the name of a function appears in an expression, it ``decays'' into a pointer (that is, it has its address implicitly taken), much as an array name does.
A prior, explicit declaration for the function (perhaps in a header file) is normally needed, as shown. The implicit external function declaration that can occur when a function is called does not help when a function name's only use is for its value.
(Continued on next question...)
Other Interview Questions
|