Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language: unsigned int a =-2; printf("%u ",a); What is the output result?
C language: unsigned int a =-2; printf("%u ",a); What is the output result?
Under the platform of 16-bit int, the output is 65534; Under the 32-bit int platform, the output is 4294967294. Take 32-bit int platform as an example, unsigned int a =-2; Under the modification of unsigned statement, the unsigned value of -2' s complement is assigned to variable A, that is, 4294967294. But the following printf("%u ",a); The output of has nothing to do with whether a is a signed number, and whether the output is a signed number is determined by the control symbol %u in "%u", where %u means that the variable A is output as an unsigned number, so the output is 4294967294. Therefore, if unsigned int a =-2; Change it to int a =-2; ,printf("%u ",a); Also output 4294967294. Even unsigned int a = 4294967294 defines a as follows, using printf("%d ",a); The output is-2; Because the output is determined by the control character% d.