使用函数指针时一定要注意,因为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\n",k);

return 0;}




相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-06-02
猜你喜欢
  • 2021-12-05
  • 2021-12-05
  • 2021-10-22
  • 2021-08-26
  • 2021-11-03
相关资源
相似解决方案