I have a question about chars in C. I know that chars are integer represented with 8 bits (1 byte). So, we can represent numbers from 0 up to 255.
If in fact we write a function printbits(char c) and call printbits(255) we get 11111111.
in the same way, 87=01010111and 88= 01011000. if we then write this code:
OK never gets written. the reason is that 87+88 evaluates to 10101111 and is automatically interpreted as -81, a negative number. This means that the result is interpreted in 2's complement.Code:char a= 87,b=88; char c=a+b; if (c>100) printf("OK");
Actually, if we say that chars are integers, this would make sense. But what i cannot understand is why the 255 is evaluated correctly then..? Is it casted to something like an unsigned?
thanks for lighting my mind!