+ 3
C program....why does this program returns size 8?
Sizeof structure https://code.sololearn.com/cSFHc6nV4By9/?ref=app
4 Respuestas
+ 6
An integer has 4 bytes = 32 bits. Your struct uses 5 bits of an unsigned int for d and 4 bits for m. d + m need only 9 bits, so they can be stored in one int. y is another int so the struct has two integers in total. 2 integers = 8 bytes
+ 3
Very cool, I didn't know one can specify the number of bits explicitely 😱
+ 3
Matthias Those are called bit fields
https://www.tutorialspoint.com/cprogramming/c_bit_fields.htm
+ 2
Thank you!