[C Language] function pointer
A pointer can point to a variable, an array, or a function. A function pointer is a pointer to a function. The function name is actually the starting address of the program in the memory. The pointer to the function can pass the address to the function or return the pointer to the function from the function. For example, a function is used to calculate the sum of two numbers and call the function through the function pointer. # Include <stdio. h> int sum (int a, int B); // Declaration of the summation function void main () {int a, B; int (* fun) (int, int ); // declare a function pointer printf ("enter two integers:"); scanf ("% d, % d", & a, & B ); printf ("the first method to call a function: the function name calls the sum function: \ n"); printf ("% d + % d = % d \ n", a, B, sum (a, B); // call fun = sum through the function name; // The function pointer points to the summation function printf ("the second method to call a function: function pointer calls the summation function: \ n "); printf (" % d + % d = % d \ n ", a, B, (* fun) (, b); // call the function through the function pointer} int sum (int m, int n) // the result of the {return m + n;} program running is as follows: the statement int (* fun) (in T, int); declares a pointer variable pointing to the function and returns an integer value. There are two integer parameters. Statement fun = sum indicates that the function pointer fun points to the function sum. both fun and sum point to the start address of the function sum. during compilation, the program is translated into a line of commands and loaded into the memory area. The statement (* fun) (a, B) in the main function is used to call the summation function. You can also write it as fun (a, B) because the function itself is an address.