F
FlyingBird
I tried a simple program as follows:
int main(void) {
unsigned char x = 129;
signed char y = 127;
printf("~x = %d\n", ~x);
printf("~y = %d\n", ~y);
return 0;
}
it printed out:
~x = -130
~y = -128
Since x is an one-byte unsigned char and its range should be [-127,
+127], is it because that x was first promoted to int and then ~x got
evaluated to -130 in 2's complement? Thanks for any hints. Is it true
that all chars (char, unsigned char and signed char) would be promoted
to int when getting involved in computation?
~xg
int main(void) {
unsigned char x = 129;
signed char y = 127;
printf("~x = %d\n", ~x);
printf("~y = %d\n", ~y);
return 0;
}
it printed out:
~x = -130
~y = -128
Since x is an one-byte unsigned char and its range should be [-127,
+127], is it because that x was first promoted to int and then ~x got
evaluated to -130 in 2's complement? Thanks for any hints. Is it true
that all chars (char, unsigned char and signed char) would be promoted
to int when getting involved in computation?
~xg