1

I have countered a problem about use function pointer

typedef int (*zly)(int,int);

struct fuc{
   zly name;
};

int zzc(int a,int b){ 
    return b - a;
}

int mfc(zly z,int a,int b){ 
    return z(a,b);
    //return (*z)(a,b);
}

int main(){
   struct fuc *s = malloc(sizeof(struct fuc));        
   //s->name = &zzc;
   s->name = zzc;
   int res = mfc(s->name, 5,10); 
   printf("%d\n",res);

   // two has same address. 
   printf("%x -- %x \n",&zzc,zzc);

}

I want to know the difference between s->name = &zzc and s->name = zzc ?

Thank you .

lanyun
  • 141
  • 1
  • 4
  • 10
  • 3
    Both are the same as `s->name = ***zzc`, but you need to get a paid certificate before you're a three-star programmer. – Kerrek SB Dec 31 '13 at 02:23
  • Come on, 1.5 million questions on stackoverflow, and you don't think this might be one of them already? – Kaz Dec 31 '13 at 02:29
  • @Kaz you are right, I will search it before I ask it,thank you. – lanyun Jan 09 '14 at 06:44

0 Answers0