9 AnswersNew Answer
A bit field is a data structure used in computer programming. It consists of a number of adjacent computer memory locations which have been allocated to hold a sequence of bits, stored so that any single bit or group of bits within the set can be addressed...
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.
Bit field = a uniquely C programming language feature to assign names to certain bit positions in an int typed variable Bit fields are much easier to use than bit operations with & and | operators because: We can access the field by using the field name !
Thanks all for this... I read it but any example would be of great help
U can understood much better read this post https://www.google.com/amp/s/www.geeksforgeeks.org/bit-fields-c/amp/
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
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
But does this help in structure padding ? If not, what purpose it helps ? And accessing memory is not in our hand.. Isn't it?
My structure padding code is below: https://code.sololearn.com/c4na2St2ZDgQ/?ref=app Does bit can be useful here or not? How