C语言结构体里的成员数组和指针

struct test{
    int i;
    char *p;
};

 struct test *str;
    int a = 1;
    char *b = "ioiodddddddddddd";

    str = (struct test *)malloc(sizeof(struct test));//结构体指针不为null
    str->i = a;
    str->p = b;
    printf("%s
",str->p);  //输出ioiodddddddddddd
return 1;

--------------------------------------------------------
struct test{
int i;
char s[10];
};
struct test *str;
str = (struct test *)malloc(sizeof(struct test));//结构体指针不为null
printf("%x ",str); //输出 72403170
printf("%x ",str->s); //输出 72403174
return 1;

 参考:http://developer.51cto.com/art/201404/434678_all.htm

总结:不管结构体指针是否为null,访问结构体成员数组得到的其实都是成员数组的相对地址;访问成员指针得到的是相对地址存储的变量(地址)所指向的内容。 

原文地址:https://www.cnblogs.com/heyijing/p/6006351.html