Simple Character Interpretation In C

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

    char is 8 bits, signed. It can only hold values -128 to 127. When you try and assign 129 to it you get the result you see because the bit that indicates signing is flipped. Another way to think of it is that the number "wraps" around.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题