+ 3

C program....why does this program returns size 8?

Sizeof structure https://code.sololearn.com/cSFHc6nV4By9/?ref=app

15th Jun 2019, 3:38 AM
Abhijeet Pawar
Abhijeet Pawar - avatar
4 Answers
+ 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
15th Jun 2019, 5:25 AM
Anna
Anna - avatar
+ 3
Very cool, I didn't know one can specify the number of bits explicitely đŸ˜±
15th Jun 2019, 7:11 AM
Matthias
Matthias - avatar
15th Jun 2019, 7:16 AM
Anna
Anna - avatar
+ 2
Thank you!
15th Jun 2019, 5:36 AM
Abhijeet Pawar
Abhijeet Pawar - avatar