When I print the size of a union like this:
union u {
char c[5];
int i;
} un;
using this:
int _tmain(int argc, _TCHAR* argv[])
{
printf("size of union = %d ",sizeof(un));
return 0;
}
I get an answer of 8 using Visual C++, but I expected 5. Why?
Well, for the same example,
i did something like this:
int i1 = 0x98761234;
un.i = i1;
printf("
un.c[0] = %x ",un.c[0]);
printf("
un.c[1] = %x ",un.c[1]);
printf("
un.c[2]= %x ",un.c[2]);
printf("
un.c[3] = %x ",un.c[3]);
printf("
un.c[4] = %x ",un.c[4]);
printf("size of union = %d ",sizeof(un));
i got results like
un.c[0] = 34;
un.c[1] = 12;
un.c[2] = 76;
un.c[3] = ffffff98;
why are there 6fs at un.c[3]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…