How bit field store in memory?.

Discussion in 'The Projects Forum' started by tej1200, Jun 27, 2013.

  1. tej1200

    Thread Starter New Member

    Jun 26, 2013
    5
    0
    How bit field store in memory?.Is store left to right or right to left?
    example:
    struct stud
    {
    unsigned int x:5;
    unsigned int y:5;
    unsigned int z:6;
    };
    struct stud bit={1,3,3};

    How o/p of below program is 12.

    #include<stdio.h>
    #include<conio.h>
    void main
    {
    struct stud
    {
    unsigned int x:5;
    unsigned int y:5;
    unsigned int z:6;
    };
    struct stud bit={1,3,3};
    char *p;
    clrscr();
    p=&bit;
    p++;
    printf("%d",*p);

    }
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    It may be stored either way. You could write a test program to explore how your particular compiler does it. Chances are if you keep to that compiler your code will not break over the following compiler revisions.
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    According to "The C Programming Language" by Kernighan & Ritchie say this about the bit fields
     
Loading...