On a little-endian machine, bit structure will be represented as: 0x00 00 00 45
which is bit.bit4 = 0010 (2 in decimal) bit.bit3 = 0010 (2 in decimal) bit.bit1 = 1 (1 in decimal) since bit.bit1 exists at the rightmost position, while displaying data as integer, compiler just repeats the same bit to all the remaining positions making it 0xffffffff (-1). You can confirm it while setting bit.bit1 to 0 -Dinesh Bansal On Tue, Aug 9, 2011 at 12:24 PM, Rohit Srivastava <access2ro...@gmail.com>wrote: > #include<stdio.h> > #include<conio.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); > getche(); > return 0; > } > the above code gives output : -1 2 2 > any idea why??? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > -- Dinesh Bansal The Law of Win says, "Let's not do it your way or my way; let's do it the best way." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.