传值问题

来源:互联网 发布:手机防辐射软件 编辑:程序博客网 时间:2024/06/06 20:32
#include<stdio.h>
int inc(int a)
{
   return (++a);
}

int multi(int *a,int *b,int *c)

  return (*c=*a* *b);
}

typedef int (*FUNC1)(int in);//定义一个函数指针FUNC1,这个函数带有1个int , 返回int型.
typedef int (*FUNC2)(int*,int*,int*);//定义一个函数指针FUNC2,这个函数带有3个int *, 返回int型.

void show(FUNC2 fun,int arg1,int *arg2)
  FUNC1 p=&inc;//FUNC1类型 函数指针p 指向函数inc的首地址
  int temp=p(arg1);//此时调用函数inc,参数为10,返回值为11
  fun(&temp,&arg1,arg2);//调用函数multi,参数为(11,10,arg2) arg2为指针变量负责带回返回值
  printf("%d\n",*arg2);//输出 110
}

int main()

   int a;
   show(multi,10,&a);
   getchar();
   return 0;
}

若这样定义typedef int(FUNC1)(int in);那么把FUNC1 p = inc;改成FUNC1 *p = inc;