C语言函数指针的使用

使用函数指针时一定要注意,因为c不会检查参数是否正确

区分返回指针的函数和函数指针

int *f4();返回一个整数指针

int (*f5)();返回整数的函数指针

int * (*f6)();返回整数指针的函数指针


传递函数指针例子

#include<stdio.h>

int add(int a,int b){

return a+b;

}

int sub(int a,int b){

return a-b;

}

typedef int(*op)(int,int)  

int   cz(op o,int a,int b){

return o(a,b);

}

int main(){

int k=cz(add,5,5);

printf("%d ",k);

return 0;}