[prev] 82 [next]

Exercise 15: Bit-fields

What do you think the following will do? How can we fix it?

struct time{
    int hours: 5;
    int mins: 6;
    int secs: 6;
};
int main(void){
    struct time t = {22,12,20};
    printf("%d:%d:%d\n",t.hours,t.mins,t.secs);
    return 0;
}