Assuming an unsigned char
type, 0xff
would give the decimal value 255. Add one to that and you get 256, or 0x100
or 256. This would be printed out as 100
if you had manipulated std::cout
to print in hex with std::cout << std::hex;
Assuming an 8-bit signed char
, 0xff
would overflow, giving -1. Add 1 to that and you would get 0.
4
solved c++: why char c = 0xff and int n = c+1 get the result of 100? [closed]