#include <stdio.h>
int main(void)
{
char a, b;
int c;
b = 2;
a = 127;
c = a + b;
printf("%d", c);
}
i thought the value of the c should be -127 ,but actually when i run this test,the value is 129.
according to an example from <<c pragramming:a morden approach>>
,
long int i;
int j=1000;
i=j*j; /*overflow may occur,correct writing is i=(long)i*i;
here is the explain of the book--When two int type values are multiplied, the result should also be int, but the result of j * j is too large to be consistent and cannot be expressed as int on some machines, resulting in overflow.
so i think in my test,the type of (a+b)
is char,because 129>127
..char cannot express 129
, which will cause overflow.
i am very confused