Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language unsigned integer
C language unsigned integer
That's because you defined A incorrectly. Unsigned integer means unsigned. You defined a symbol, so that the compiler would not assign-100 to A, but let A perform type conversion. A is unsigned, and-100 is a signed integer, so type conversion occurs, and-100 is converted to. Continue to look down

You use %d in printf, which means printing data in signed decimal form.

Signed int (compiler allows abbreviation int) is a signed integer of at least 2 bytes. Now the operating system is basically set to 4 bytes, and the value range of 4-byte int is -2 147483647 to 2 147483647.

For unsigned int, it is still 4 bytes, but its value range is 0 to 4294967295.

For signed int, he expressed unsigned int from 0 to 2 147483647 as 0 to 2 147483647, and 2 147483648 to 4294967295 as -2 147483647 to-.

So, the-100 in the first paragraph I just said didn't want to be 100, but it became an unsigned integer corresponding to-100, which was stored in A, and then you output A with %d, because %d, it changed from this unsigned integer to-1.

For unsigned int output, %u output should be used. You can keep asking me questions.