T0 add to what CPallini said, in C a
char
value is an 8-bit quantity, so it can hold values from 00000000 binary to 11111111 binary inclusive, and no other. If you add one to a value that contains 11111111 binary, it "rolls over" to 00000000 binary.
Conventionally, C
char
values are
signed
, which means that the most significant bit of the value controls if it is positive or negative - a '1' in the "top bit" indicates a negative number: 01111111 binary is 127 in decimal, 10000000 binary is -128 in decimal, and 11111111 binary is -1 in decimal.
So if you start with a
char
containing 255 and add 10 to it, what you are actually doing is adding 10 to -1:
decimal binary
x = 10 + (-1) x = 00001010 + 11111111
x = 10 - 1 x = 00001001
x = 9
Make sense now?