Item 14. Function Pointers
It’s possible to declare a pointer to a function of a particular type.
void (*fp)(int); // ptr to function
Note the required use of parentheses to indicate that fp
is a pointer to a function that returns void
, not a function that returns void*
(see Dealing with Function and Array Declarators [17, 61]). Like a pointer to data, a pointer to function may be null, or it may refer to a function of the appropriate type.
Note that it is not necessary to take the address of a function explicitly when initializing or assigning its address to a pointer to function; the compiler knows implicitly to take the function’s address, ...
Get C++ Common Knowledge: Essential Intermediate Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.