Simple Character Interpretation In C

后端 未结 9 910
暖寄归人
暖寄归人 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:29

    The type char can be either signed or unsigned, it's up to the compiler. Most compilers have it as `signed.

    In your case, the compiler silently converts the integer 129 to its signed variant, and puts it in an 8-bit field, which yields -127.

提交回复
热议问题