0

I'm reading about structs in C and I came across some interesting declaration that I don't know what does is mean. The declaration goes as follows:

typedef struct name{
   int x :1;
}name;

what does line 'int x :1;' mean ? is 1 the default value of x?

Would appreciate help! Thanks

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
john lii
  • 3
  • 2
  • Please don't add tags for multiple very different languages unless both are involved. – Gerhardh Nov 11 '21 at 08:17
  • The term to look up is "bitfield". You can squeeze multiple members into same `int` member by specifying a bit size. Beware: They are implementation defined. – Gerhardh Nov 11 '21 at 08:19

1 Answers1

0

It specifies the number of bits to use for that field. It is called "bit field".

Check this: https://en.cppreference.com/w/cpp/language/bit_field