What is -(-128) for signed single byte char in C?

后端 未结 3 1136
再見小時候
再見小時候 2021-01-18 06:45

My little program:

#include 

int main() {
    signed char c = -128;
    c = -c;
    printf(\"%d\", c);
    return 0;
}

prin

3条回答
  •  遥遥无期
    2021-01-18 07:42

    because a byte(char) can't hold 128

    -128 = 0x80
    

    what neg do is reverse it and plus 1

    -(-128) = (~0x80) + 1 = 0x7F + 1 = 0x80
    

    daha, you got 0x80 again

提交回复
热议问题