函数指针的一种用法

 1#include <stdlib.h>
  2 #include <stdio.h>
  3
  4
  5 typedef int(*sum)(int *a, int *b);
  6 sum  fun_sum = NULL ;
  7
  8 int add(int *a, int *b)
  9 {
 10   int c = 0;
 11   c = (*a) + (*b);
 12   printf(" c = %d\n",c);
 13
 14   fun_sum = NULL;
 15   printf("fun_sum = NULL\n");
 16
 17   return c;
 18
 19
 20 }
 21
 22 int main(void)
 23 {
 24  int a = 10;
 25  int b = 20;
 26  int d = 0;
 27
 28  fun_sum = add;
 29
 30  d = fun_sum(&a,&b);
 31  
 32  printf("sum d = %d\n",d);
 33
 34 return 0;
 35
 36
 37
 38 }

猜你喜欢

转载自blog.csdn.net/Lq19880521/article/details/79467484