pointer to member of struct [closed]
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.
精彩评论