#include <stdio.h>
#include <string.h>
struct test_t{
int a;
unsigned b:1;
int c;
};
int main()
{
char a;
int b=0x0102;
int c=0x0201;
a = b;
printf("a=%x\n", a);
struct test_t t;
printf("t=%d\n", sizeof(t));
memset(&t, 0, sizeof(t));
t.b = b;
printf("t.b=%d\n", t.b);
t.b = c;
printf("t.b=%d\n", t.b);
return 0;
}
输出结果:
a=2
t=12
t.b=0
t.b=1