To put Damien's answer in simpler terms:
Compound operators (e.g. +=
, -=
etc.) automatically cast the result to the targeted type (if possible).
Therefore c += 'a'
works, because it is evaluated as c = (char)(c + 'a')
.
In this case, the conversion is necessary, because the return-type of arithmetic operations between chars is int
(which is why c = c + 'a'
does not compile, as it is missing the cast above).