Simple Character Interpretation In C

后端 未结 9 731
暖寄归人
暖寄归人 2021-01-06 12:54

Here is my code

 #include

 void main()
 {
     char ch = 129;
     printf(\"%d\", ch);
 }

I get the output as -127. What d

9条回答
  •  别那么骄傲
    2021-01-06 13:18

    On your system: char 129 has the same bits as the 8 bit signed integer -127. An unsigned integer goes from 0 to 255, and signed integer -128 to 127.

    Related (C++):

    You may also be interested in reading the nice top answer to What is an unsigned char?

    As @jmquigley points out. This is strictly undefined behavior and you should not rely on it. Allowing signed integer overflows in C/C++

提交回复
热议问题