&((struct s*)0)->d的相关详解

#include <stdio.h>

struct s
{
 int a;
 int b;
 int c;
 char d;
};
void main()
{
 printf("%d",&((struct s *) 0)->a);        //把结构体s的起始位置视为0,返回结构体s的成员a的位置【输出结果为0】    

printf("%d",&((struct s *) 0)->b);        //把结构体s的起始位置视为0,返回结构体s的成员b的位置【输出结果为4】

printf("%d",&((struct s *) 0)->c);        //把结构体s的起始位置视为0,返回结构体s的成员c的位置【输出结果为8】

printf("%d",&((struct s *) 10)->c);        //把结构体s的起始位置视为10,返回结构体s的成员c的位置【输出结果为18】

printf("%d",&((struct s *) 10)->d);        //把结构体s的起始位置视为10,返回结构体s的成员d的位置【输出结果为22】
}

注:int类型占4个字节大小的空间

posted @ 2022-07-14 11:15  gǒが油メo  阅读(501)  评论(0)    收藏  举报