1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <stdio.h> typedef struct tm{ unsigned int a; }TM; typedef struct hp{ char a; unsigned char b; TM *t; unsigned short c; unsigned long d; }HP;
int main(int argc, char *argv[]) { HP hp={ .a=0xa1, .b=0xb1, .c=0xc1c2, .d=0x1, }; unsigned char *p=&hp; printf("sizeof(HP) = %lu\n",sizeof(HP) ); for (unsigned long i = 0; i < sizeof(HP); ++i) { printf("%02x ",p[i] ); if((i+1)%8==0) printf("\n"); } unsigned int d=hp.d; printf("%d",d); return 0; }
|