print bit type as integer? How is the conversion?

Viewed 284

the program is :

typedef struct xp {
        int a:2;
        int b:2;
        int c:1;
} xp;

int main(void)
{
        xp x;
        memset(&x, 0, sizeof(xp));

        x.a = 1;
        x.b = 3;
        x.c = 1;

        printf("%d\n",x.a);
        printf("%d\n",x.b);
        printf("%d\n",x.c);

        return 0;
}

I get 1 -1 -1, why? How are a, b and c stored in x? What happened when printf("%d\n",x.a); is executed?

2 Answers
Related