struct abc
{
int bit1:1;
int bit3:4;
int bit4:4;
}xyz(1,2,2);
These are packed bit fields. The number after the colon is the length. The compiler will pack these into an integer if possible. Usually this is only needed if memory is at a premium. Generally it is best to use unsigned int instead of int so no bits are added for the sign.
So in the xyz variable,
xyz.bit1 = 1 and is 1 bit long
xyz.bit3 = 2 and is 4 bits long
xyz.bit4 = 2 and is 4 bits long
All the above values will be automatically converted to int.
I don't know what happened to bit2. But it could have been set to a 7 bit variable without increasing the memory use.
Use bit fields with caution as they are not very portable between platforms (int16 vs 1in32).
The definition of 'int' is platform dependent, i.e. it depends on what compiler you're using since compilers are free to set the size of int.
My explanation was assuming that an integer was 16 bits and by adding a bit2 of 7 bits long, the total bits used would be 16
If you're writing code for the PC, more than likely your compiler has 32 bit integers. Some microprocessor compilers have 16 bit integers. I haven't ever used a C compiler with 8 bit 'int' that supports bit fields.