1 代码偏移指令offsetof
#include <stddef.h> #include <stdio.h> struct address { int aa; int bbb; int name[50]; char street[50]; int phone; }; int main() { printf("address 结构中的 name 偏移 = %ld 字节\n",offsetof(struct address, name)); printf("address 结构中的 street 偏移 = %ld 字节\n",offsetof(struct address, street)); printf("address 结构中的 phone 偏移 = %ld 字节\n",offsetof(struct address, bbb)); return(0); }