#include<stdio.h>
#include<stddef.h>
struct Person
{
char a;
int b;
};
struct Person2
{
char c;
int d;
struct Person e;
};
void test01() {
struct Person2 p2 = {'c',10,'a',20};
int offset1 = offsetof(struct Person2,e);
int offset2 = offsetof(struct Person,b);
printf("Person结构体中的b的值是:%d\n",*((int*)((char *)&p2+offset1+offset2)));
}
int main(void) {
test01();
return 0;
}
c/c++ 结构体嵌套结构体的偏移量计算
最新推荐文章于 2022-05-10 11:22:30 发布