1.解题思路:
首先,结构体首个变量偏移量为0,那么就可以假定将首元素的首地址在0处,那么往后每个元素的偏移量就为每个元素的地址,这样一来,取地址就可获得偏移量
#define _CRT_SECURE_NO_WARNINGS 1 #define Move(type,meber) (size_t)&(((type*)0)->meber) #include<stdio.h> typedef struct Circle { int ridius; int x; int y; } Circle; int main() { struct Circle c = {100,50,50}; int x1=Move(Circle, ridius); int y = Move(Circle, x); int z = Move(Circle, y); printf("%d %d %d", x1, y, z); return 0; }