struct x
{
char a : 1; // statement 1
char c : 3; // statement 2
};
what will be the size if this structure. What is the meaning of statement 1 and 2?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Those statements declare Bit fields.
It means
aoccupies memory of1bit andcoccupies memory of3bits.The size of the structure will be:
Atleast 4 bits
+ padding(bits)
And Most likely, it will be
8 bitsi.e:1 byteBecause,
If a series of bit fields does not add up to the size of an int, padding can take place. The amount of padding is determined by the alignment characteristics of the members of the structure.
What are Bit Fields?
From IBM documentation: