+ 2
what is bit fields in structure
Hi Can anyone help me to understand importance of bit fields? What does it mean and how it is useful?
9 Respostas
+ 3
A structure or a C++ class can contain bit fields that allow you to access individual bits. You can use bit fields for data that requires just a few bits of storage. A bit field declaration contains a type specifier followed by an optional declarator, a colon, a constant expression, and a semicolon.
+ 2
Thanks all for this... I read it but any example would be of great help
+ 1
U can understood much better read this post https://www.google.com/amp/s/www.geeksforgeeks.org/bit-fields-c/amp/
+ 1
Bit fields are important for two main reasons:
1.Allows you to manipulate individual bits using a field name.(just as AMOGHA. A. K. has said)
2.unnamed bit fields are used to align the data in structs in a machine dependent way
+ 1
Finally come up with use case when bit field can be applied to save memory
https://code.sololearn.com/c7L891KF9TXI/?ref=app
Thanks all of you for your time and help
0
But does this help in structure padding ? If not, what purpose it helps ? And accessing memory is not in our hand..
Isn't it?
0
My structure padding code is below:
https://code.sololearn.com/c4na2St2ZDgQ/?ref=app
Does bit can be useful here or not? How