C-programming - Bit fields, Using bit fields in structures

Bit fields


It is possible to allocate lesser memory for variables than the compiler would ordinarily allocate. For example integer usually requires 4 bytes OF memory but when the value is very small large memory becomes a waste therefore using bit fields we can use memory efficiently.

struct display
int a:8;
int b:4;
int c:6;

Here, int type variable a,b,c takes only 8 bits, 4 bits and 6 bits respectively. There is a constraint that we cannot get values in run time to bit field variables. If necessary we can get value in other variable and store it in these variables.

The topic on C-programming - Bit fields is posted by - Math

Hope you have enjoyed, C-programming - Bit fieldsThanks for your time

Tech Bluff