I came across this syntax which i have not seen before
struct A {
int x:24;
};
What does x:24 mean ? In C++ can you specify compiler that a variable should occupy only 24 bits, instead of 32 for an int type? If yes, which 24 bits will be occupied? the left most or the right most?
There are two types of variable-length data types. These are real variable-length data types, like char and binary, and nullable data types, which have either a normal fixed length that corresponds to their type or to a special length if null.
The size of float (single precision float data type) is 4 bytes. And the size of double (double precision float data type) is 8 bytes.
In the above example, '@' and '23' are also of type str (str is for String). Look at another example. You can see that the data type of the value assigned to a is str because it is written within "" . Even a digit written within ' ' or " " is treated as a string and not as an integer or a float.
This is the bit fields feature. It has been available since the early C days. Microsoft has a nice write-up on this feature, complete with pretty pictures showing the layout which is compiler-specific (they say that the pic is specific to MS).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With