69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
typedef void(*p)(int n,int a,int b);
void f(int n,char *s)
{
printf("hello\n");
}
void main(void){
float num;
p P;
P = f;
P(1,2,3);
}
与函数的参数无关(大多数用到形参的时候保持一致),函数指针指向的函数的代码的首地址而已
#include <stdio.h>
void fun(int n,char *s)
{
printf("hello %s\n", s);
}
int main(int argc, char *argv[])
{
void (*pf1) (int,char);
void (*pf2)();
void* pf3();
void* pf4();
pf1=&fun;
pf2=fun;
//*pf3=fun;
//pf4=fun;
pf1(1, "world");
pf2(2, "man");
pf2();
return 0;
}
#include<stdio.h>
int main()
{
int max(int x,int y);
int(*p)();
int a,b;
p=max;
a=max(1,2);
b=(*p)(1,2);
printf("%d\n",a);
printf("%d\n",b);
return 0;
}
int max(int x,int y)
{
return (x+y);
}
自己写了个函数,希望有助于你的理解。