Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - A C language question that has troubled me for a long time, a small program
A C language question that has troubled me for a long time, a small program

if(t<=32)

t is a character type and only occupies 8 bits. The highest bit is the sign bit. When i=2, s[i]*11% The value of 256 is 131, and the highest binary bit is 1, so the system interprets it as a negative number -125, so t<=32 is established, so s[i]=t will not be executed, and the situation is the same when i=3. So the original element value is not modified.

if(s[i]*11%256<=32)

s[i] is a character type, and 11 and 256 are both integer types, so s[i] Integer promotion will be performed, and the type will be automatically converted to an integer. The integer must be at least 16 bits (all are 32 bits in current systems), so when i=2, the value of s[i]*11%256 is 131. Therefore (s[i]*11%256<=32) is not true, so we need to perform the operation of s[i]=t to convert 131 to char type, that is, a negative number is assigned to s[i], and the negative ASCII The code in GBK encoding is the encoding of Chinese characters. The situation is the same when i=3, so Chinese characters will be output.