指向函数的指针

一个简单的demo,指针变量用来指向函数的入口地址

#include <stdio.h>



int sum(int a, int b)

{

    return a + b;

}



int minus(int a, int b)

{

    return a - b;

}



int mul(int a, int b)

{

    return a * b;

}



int count(int (*p)(int, int), int a, int b)

{

    return p(a, b);

}



int main()

{

    int a = 6;

    int b = 9;



    printf("%d+%d=%d\n", a, b, count(sum, a, b));

    printf("%d-%d=%d\n", a, b, count(minus, a, b));

    printf("%d*%d=%d\n", a, b, count(mul, a, b));



    return 0;

}

 

 

你可能感兴趣的:(函数)