写一个这样的 C 程序:
#include <stdio.h>
#include <stdint.h>typedef struct WTF {uint8_t a;uint8_t b;uint8_t c;uint8_t d;
} WTF;int main() {WTF wtf;printf("hello world\n");printf("wtf.a addr = %p\n", &(wtf.a));printf("wtf.b addr = %p\n", &(wtf.b));printf("wtf.c addr = %p\n", &(wtf.c));printf("wtf.d addr = %p\n", &(wtf.d));return 0;
}
编译运行,日志如下:
hello world
wtf.a addr = 0x7ffe64b700e4
wtf.b addr = 0x7ffe64b700e5
wtf.c addr = 0x7ffe64b700e6
wtf.d addr = 0x7ffe64b700e7
说明结构体中,排前面的成员在低地址,排后面的成员是高地址