Introducing operations on characters
The integer value of the letter 'a'
is 97
. When we treat that value as a char, the 97
value becomes 'a'
. Since characters are internally represented as integers, any of the integer operations can be applied to them too. However, only a couple of operations make sense to apply to characters – the additive operators (that is, addition and subtraction). While multiplying and dividing characters are legal, those operations never produce any practical or useful results:
char - char
yieldsint
. The result represents the distance between characters.char + int
yieldschar
. This yields the character that is the specified distance from the original character.char - int
yieldschar
. This also yields the character that is the specified distance from the original character.
So, 'a' + 5
is 'f'
; that is, 97 + 5
is 102
, which as a character is 'f'
. 'M' - 10
is 'C&apos...