One of the usual uses of function pointer variables is to pass pointers as parameters to other functions.
Examples of calling function pointers:
int int (*compare) (elemtype*, elemtype*))
Where compare is the function pointer name, (elemtype*, elemtype*) is the parameter of the function pointer.
Examples of calling function pointers:
if 0 ) return i;
The parameters &e1 and &e2 are two variables of type elemtype*.
Second, for example application
The Qsort function in Stdlib.h is often used in ACM competitions, in which there is a textbook-style function pointer application demonstration.
#include <stdio.h>#include<stdlib.h>intCompConst void*a,Const void*b) { return*(int*) A-* (int*) b;}intMain () {intn =5; int*array = (int*)malloc(nsizeof(int)); inti =0; for(; i<n; i++) { * (array + i) =Ten-i; } qsort (array, N,sizeof(int), comp); for(i =0; i<n; i++) {printf ("%d\t", Array[i]); } return 0;}
Use pointers to functions as function arguments