Well, inside the struct
you defined- p:3
, c:2
, m:2
are actually denoting the bit fields. To know more about bit fields in C go through this link in SO or this link in Wikipedia.
For simplicity, know that the 3 or 2 after the colon(:) sign is representing bit-fields of width 3 or 2. That means 3 or 2 adjacent computer memory locations which have been allocated to hold a sequence of bits.
Now, inside the main()
function of your code:
struct marks s={2,-6,5};
Here,
Binary value of 2: 00000010
Binary value of -6: 11111010
Binary value of 5: 00000101
Now according to bit-fields, from binary value of 2, we will take last 3 digits which is 010 (in decimal it is 2) and from binary value of -6, we will take last 2 digits which is 10 (in decimal it is 2) and from binary value of 5, we will take last 3 digits which is 01 (in decimal it is 1) and finally assign them to p, c or m.
That's how the output comes as 2 2 1
.
Hope, I could make you clear.