+ 1

Can anyone help me out please?

#include <stdio.h> typedef struct { int bit1:1 ; int bit2:2; int bit30:30; }bits; int main() { printf("%d",sizeof(bits)); return 0; }

12th Jun 2019, 6:38 AM
Sandesh Dinkar
2 Answers
+ 7
What's your question, why the output is 8? An integer usually has four bytes = 32 bits. You're using one bit of the first int for bit1 and two more bits for bit2. There's 29 bits remaining, but bit3 takes 30 bits. So you need two integers to store all (1+2+30=) 33 bits. Two integers = 2*4 bytes = 8 bytes
12th Jun 2019, 6:53 AM
Anna
Anna - avatar
+ 1
How
25th Nov 2019, 9:28 PM
Austin Mano