How does subtracting the character ‘0’ from a char change it into an int? –
This method works in C, C++ and Java. I would like to know the science behind it.
The value of a char
can be 0-255, where the different characters are mapped to one of these values. The numeric digits are also stored in order '0'
through '9'
, but they’re also not typically stored as the first ten char
values. That is, the character '0'
doesn’t have an ASCII value of 0
. The char value of 0
is almost always the