标签:
C语言中的函数指针
函数指针的概念: 函数指针是一个指向位于代码段的函数代码的指针。
函数指针的使用:
#include<stdio.h>
typedef struct (*fun_t) (int,int);
fun_t pf;
int add(int a, int b)
{
return a+b;
}
int sub(int a,int b)
{
return a-b;
}
int mul(int a,int b)
{
return a*b;
}
int div(int a,int b)
{
return a/b;
}
int main()
{
int result1,result2,result3,result4;
pf = add;
result1 = pf(20,4);
printf("result1 is %d",result);
pf = sub;
result2=pf(20,4);
printf("result2 is %d",result2);
pf = mul;
result3 = pf(20,4);
printf("result3 is %d",result3);
pf = div;
result4=pf(20,4);
printf("result4 is %d",result4);
return 0;
}
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/5130197.html