开发者

pointer to member of struct [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I am trying to write 开发者_StackOverflow中文版a C program. I need the address of variable "recq". Can someone pls help me figure that out?

typedef struct {  
    int recq;  
} dd;  


struct test {  
    dd a;  
};

main(){  
    struct test *mm;  
    mm=(struct test *) malloc (sizeof (struct test));    
    ss=&(mm->a.recq);    
    printf("%p",ss);    

}      


What you have looks good except you need to declare the ss variable:

int *ss;


Your required program is,

#include<stdio.h>

typedef struct {
    int recq;  
} dd;  

struct test {  
    dd a;  
};

void main(void){
    struct test mm;
    printf("%p", &mm.a.recq);
} 


First of all, you need to declare ss as "int * " , or use cast whatever the rest of your code is right, I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜