EmbLogic's Blog

BIT_FIELDS

#include
#include
#include

union
{
int index;
struct
{
unsigned int x : 1;
unsigned int y : 1;
unsigned int z : 2;

} bits;
} number;

int main()
{
for (number.index = 0; number.index < 20; number.index++)
{
printf("index = %d, bits = %d %d %d\n", number.index,number.bits.z, number.bits.y, number.bits.x);
}

return 0;
}

One Response to BIT_FIELDS

  1. hemant.kumar says:

    to SIDHARTH SIR…
    i am getting the output but not able to understand it
    and union causes the bits to be stored in the same memory location..??is it true

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>