Suppose you want to design a function called estimate (), estimating the amount of time it takes to write code for a specified number of lines, and expect the function to be used by different programmers. A portion of the code in Estimate () is the same for all users, but the function allows each programmer to provide its own algorithm to estimate the time it takes to run the algorithm.
To achieve this goal, the mechanism used is to pass the address of the algorithm function that the programmer wants to use to estimate (). Therefore, you must be able to complete the following tasks:
(1) Obtain the address of the function;
(2) Declaring a function pointer;
(3) Use function pointers to invoke functions.
Double pam (int);
Double (*PF) (int); PF points to a function ' return double
double *pf (int); PF () A function that returns a pointer-to-double
The signature and return value types of Pam () must be the same as PF.
PF = pam; PF now points to the PAM () function
Double x = pam (4); Call Pam () using the function name
double y = (*PF) (5);
Double y = pf (5); Also call Pam () using the pointer pf
This means PF = = (*PF).