Bit Fields

Suppose your C program contains a number of TRUE/FALSE variables grouped in a structure called status, as

follows:

struct
{
unsigned int Member1;
unsigned int Member2;
} status1;
struct
{
unsigned int Member1 : 1;
unsigned int Member2 : 1;
} status2

Note: The number of bits in the bit-field. The width must be less than or equal to the bit width of the specified type.

int main()
{
printf( “Memory size occupied by status1 : %d\n”, sizeof(status1));
printf( “Memory size occupied by status2 : %d\n”, sizeof(status2));
return 0;
}

Output:
Sizeof( Age ) : 4
Age.age : 4
Age.age : 7
Age.age : 0

null

Mr. Sandeep Soni

Founder, Trainer & CEO, Deccansoft Software Services.

Sandeep has 21 yrs of experience working in various Microsoft Technologies/Platforms incl. VB6.0, ASP, VC++, VB.NET, C#. He is involved in managing and architecting projects at Deccansoft. He will be your liaison to Deccansoft, for any kind of communication and project updates. He knows what works and what doesn’t, and what practices are most suitable for design and programming with the ultimate goal of producing a quality system.