I have the following code and it seems to me that it should always enter the true part of the if statement but, beyond 120, it appears to start executing the else clause. Why is that happening?
char x;
for (i=0;i<256;i+=10) {
x=i;
if (x==i)
printf("%d true\n",i);
else
printf("%d false\n",i);
}
The output is:
0 true
10 true
: all numbers from 20 to 100 are true
110 true
120 true
130 false
140 false
: all numbers from 150 to 230 are false
240 false
250 false
Your compiler probably uses a signed char by default when you use the char keyword. The range of a signed char is usually -128 to 127, whereas the range of an int is far greater. More esoteric hardware beyond the typical desktop PC may use other values.