Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why do unsigned integers and unsigned short integers display negative numbers differently in C language?
Why do unsigned integers and unsigned short integers display negative numbers differently in C language?
Because when using %d to output variables in printf, the program will default the variables to int type. If the variable is an integer, but not an int, but a char or a short, the program will first convert it into an int and then pass it to printf.

So when using unsigned int a=- 12, there is no conversion step mentioned above. %d is a signed integer and the output is-12, no problem.

When the unsigned short a=- 12, note that a is 16, and in memory it is111165438+. Converting to int type will become 32 bits, and the program will add 16 zeros on the left to become 00000000011111/.