User talk:Ziqiangcheng

==  ==

Chapter 2 Primitive Build-in Types

In C++ it is perfectly legal to assign a negative number to an object with unsigned type. The result is the negative value modulo the size of the type. So, if we assign -1 to an 8-bit unsigned char, the resulting value will be 255, which is -1 modulo 256.

a mod b = c, (a + n * b) mod b = c，n [0, b-1]

so, we can -1 mod 256 = (-1 + 256) mod 256 = 255． that is, the resulting is 255, 255 will assignment to the declared variable(unsigned char).