The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Bit fields provides exact amount of bits required by the variable. Bit fields uses the memory very efficiently. The bits must be specified by non-negative(unsigned) integer type followed by a colon(:). Bit fields can also used as member in unions.
Lets code Bit Fields and have some fun.
#include <stdio.h>
int main()
{
struct sample {
unsigned int b1;
unsigned int b2;
}s1;
struct sample2 {
unsigned int b1:1;
unsigned int b2:1;
}s2;
printf("Size of structure sample : %d ", sizeof(s1));
printf("\nSize of structure sample2 : %d ", sizeof(s2));
return 0;
}
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019