Number 224, when stored in signed char
, overflows.
char
typically gets considered as signed char
and can hold values from -128 to 127. When you attempt to store a number beyond those limits, overflow occurs which causes the number to go around from the other end.
You can think of it as filling a jar with water, then emptying out the whole jar when you fill the whole jar, and then go on filling whatever you are left. In this case, you are filling a char
variable with 224
... So;
- 224 first fills 127,
- then you are left with 224 - 127 = 97,
- one more (97 - 1 = 96) and you are at -128 now,
- you end up at -128 + 96 = -32