1. 程式人生 > >C語言 函式指標的例子

C語言 函式指標的例子

#include <stdio.h>

typedef struct Foo
{
    int a;
    int b;
}Foo_t;

struct Foo f;
void *vp;

int max(Foo_t *ef,int c)
{
    return ((ef->a) > (ef->b)) ? ((ef->a)+c) : ((ef->b)+c);
}

void main()
{
    int d;
    f.a = 5;
    f.b = 10;
    int (* pfunc)(void*,int) = &max; //&可以省略
vp = &f; printf("%d\n",&f);//指標的記憶體地址 printf("%d\n",vp);//指標的記憶體地址 d = pfunc(vp,3); printf("%d\n",d);//返回(a+c)和(b+c)中的較大值 }