Struct - Explain the output:
问题 I have the following C code. struct values{ int a:3; int b:3; int c:2; }; void main(){ struct values v={2,-6,5}; printf("%d %d %d",v.a,v.b,v.c); } When I execute the code, I am getting the following output: 2 2 1. But output should be 2 -6 5 , right? If I'm wrong please explain. 回答1: -6 exceeds the range of a 3-bit signed int. Therefore you're observing an artifact of undefined implementation-defined behaviour (in practice, the most-significant bits of your value are being thrown away). 回答2: