1. i think if the total no of bits is within no of bits in a int , the size will b same as int .
here total bits 3 < 32 (bits in int according to gcc, in Turbo c its 16) so size of structure will be 4(in gcc), 2 (in TC) if total no of bits is 40 (suppose) than size will be 8(in GCC) , 4(in TC) 2. By default int is considered as signed int if in n bits signed int is stored than the range will be -2^(n-1) to 2^(n-1)-1 so for bit1:1 range is -1,0 so for bit2:4 range is -8,7 so for bit3:4 range is -8,7 if the assigned value exceed than it will rotate as per conversion from unsigned to signed int (hope u know this) bit1 cant hold 1 .it ll store as -1 others within range so it ll output as -1 4 4 3. Yea u can have 3 bitfields in union ...but u can initilize only one at a time her sizeof union will be always sizeof int bcoz u can use only one variable at a time in union and u cant declare bitfield of more than bits of an int (u wil be compile time error) On 6/13/10, divya <sweetdivya....@gmail.com> wrote: > tell the o/p of following with explanations > > 1. #include<stdio.h> > int main() > { > struct value > { > int bit1:1; > int bit3:4; > int bit4:4; > }bit; > > printf("%d\n",sizeof(bit)); > return 0; > } > > 2. > #include<stdio.h> > int main() > { > struct value > { > int bit1: 1; > int bit3: 4; > int bit4: 4; > } bit={1,2,2}; > printf("%d %d %d\n",bit.bit1,bit.bit3,bit.bit4); > return 0; > } > > 3 can bit field be used in union?? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.