自己分析
哪里看不懂,问我^_^
#include <stdio.h>
#include <stddef.h>
struct text
{
int a;
char b;
float c;
union u
{
char u1[5];
int u2[2];
} ua;
};
int main(void)
{
printf("struct text size: %d\n", sizeof(struct text));
putchar('\n');
printf("a offset : %d\n", offsetof(struct text, a));
printf("b offset : %d\n", offsetof(struct text, b));
printf("c offset : %d\n", offsetof(struct text, c));
printf("u1 offset : %d\n", offsetof(struct text, ua.u1));
printf("u2 offset : %d\n", offsetof(struct text, ua.u2));
putchar('\n');
struct text tmp;
printf("ua size: %d\n", sizeof(tmp.ua));
return 0;
}
struct text size: 20
a offset : 0
b offset : 4
c offset : 8
u1 offset : 12
u2 offset : 12
ua size: 8
请按任意键继续. . .
|