when i watch a video about bit fileds to understand it
the teacher who made the video he wrote this:
Code:
struct
{
int member : 3;
}d1;
d1.member=7;
and he said that: d1.member is can stored 7(cause you specify 3bits to use it )and he run the program and the out put was 7 it works normally.
the problem when i copy his program in my compiler code blocks
i surprised because the out put was -8 and it's different from the first ...i creat some program to understand what happning and finally i found that out :
when we write this
Code:
struct
{
int member : 3;
//it means we use just 2 bits for store the number and last one is for sign(negative or positive number).
}d1;
so the greatest value we can store it in d1.member is 3 not 7.
where's the right ?