1、什么是函数指针?
    如果程序定于了一个函数,那么在编译时系统会为这个函数代码分配一段存储空间,这段存储空间的首地址称为这个函数的地址。函数名表示的就是这个地址。
    2、如何定义函数指针变量?

    1. //函数返回值类型(*指针变量名)(函数参数列表);
    2. int(*p)(int,int);

    第一个int表示的是返回值,后两个int表示这个指针变量可以指向两个int参数

    函数指针无法++或者—。
    3、如何使用函数指针

    1. # include <stdio.h>
    2. int Max(int, int); //函数声明
    3. int main(void)
    4. {
    5. int(*p)(int, int); //定义一个函数指针
    6. int a, b, c;
    7. p = Max; //把函数Max赋给指针变量p, 使p指向Max函数
    8. printf("please enter a and b:");
    9. scanf("%d%d", &a, &b);
    10. c = (*p)(a, b); //通过函数指针调用Max函数
    11. printf("a = %d\nb = %d\nmax = %d\n", a, b, c);
    12. return 0;
    13. }
    14. int Max(int x, int y) //定义Max函数
    15. {
    16. int z;
    17. if (x > y)
    18. {
    19. z = x;
    20. }
    21. else
    22. {
    23. z = y;
    24. }
    25. return z;
    26. }

    4、回调函数
    无参回调函数

    1. #include<stdio.h>
    2. int Callback_1() // Callback Function 1
    3. {
    4. printf("Hello, this is Callback_1 ");
    5. return 0;
    6. }
    7. int Callback_2() // Callback Function 2
    8. {
    9. printf("Hello, this is Callback_2 ");
    10. return 0;
    11. }
    12. int Callback_3() // Callback Function 3
    13. {
    14. printf("Hello, this is Callback_3 ");
    15. return 0;
    16. }
    17. int Handle(int (*Callback)())
    18. {
    19. printf("Entering Handle Function. ");
    20. Callback();
    21. printf("Leaving Handle Function. ");
    22. }
    23. int main()
    24. {
    25. printf("Entering Main Function. ");
    26. Handle(Callback_1);
    27. Handle(Callback_2);
    28. Handle(Callback_3);
    29. printf("Leaving Main Function. ");
    30. return 0;
    31. }

    含参回调函数

    1. #include<stdio.h>
    2. int Callback_1(int x) // Callback Function 1
    3. {
    4. printf("Hello, this is Callback_1: x = %d ", x);
    5. return 0;
    6. }
    7. int Callback_2(int x) // Callback Function 2
    8. {
    9. printf("Hello, this is Callback_2: x = %d ", x);
    10. return 0;
    11. }
    12. int Callback_3(int x) // Callback Function 3
    13. {
    14. printf("Hello, this is Callback_3: x = %d ", x);
    15. return 0;
    16. }
    17. int Handle(int y, int (*Callback)(int))
    18. {
    19. printf("Entering Handle Function. ");
    20. Callback(y);
    21. printf("Leaving Handle Function. ");
    22. }
    23. int main()
    24. {
    25. int a = 2;
    26. int b = 4;
    27. int c = 6;
    28. printf("Entering Main Function. ");
    29. Handle(a, Callback_1);
    30. Handle(b, Callback_2);
    31. Handle(c, Callback_3);
    32. printf("Leaving Main Function. ");
    33. return 0;
    34. }