Common explanations of callback functions:
Common functions: the functions you write call system functions. You only need to call them, regardless of implementation.
Callback function: the system calls the function you write. You only implement the function, regardless of the call.
The following is an example of using the C language to implement a callback function:
Code:
# Include <stdio. h> void printnum (int n); void shownum (int n, void (* PTR) (); void printmessage1 (); void printmessage2 (); void printmessage3 (); void showmessage (void (* PTR) (); int main () {shownum (11111, printnum); shownum (22222, printnum); showmessage (printmessage1 ); showmessage (printmessage2); showmessage (printmessage3);} void printnum (int n) {printf ("test1 is called, the number is % d \ n", n );} void shownum (in T n, void (* PTR) () {(* PTR) (n);} void printmessage1 () {printf ("this is the message 1! \ N ");} void printmessage2 () {printf (" this is the message 2! \ N ");} void printmessage3 () {printf (" this is the message 3! \ N ");} void showmessage (void (* PTR) () {(* PTR )();}
Running result: