Both the character literal 'A'
and the integer literal 0x41
have type int
. Therefore, the only situation where they are not exactly the same is when the basic execution character set is not ASCII-based, in which case 'A'
may have some other value. The only non-ASCII basic execution character set you are ever likely to encounter is EBCDIC, in which 'A' == 0xC1
.
The C standard does guarantee that, whatever their actual values might be, the character literals '0'
through '9'
will be consecutive and in increasing numerical order, i.e. if i
is an integer between 0 and 9 inclusive, '0' + i
will be the character for the decimal representation of that integer. 'A'
through 'Z'
and 'a'
through 'z'
are required to be in increasing alphabetical order, but not to be consecutive, and indeed they are not consecutive in EBCDIC. (The standardese was tailored precisely to permit both ASCII and EBCDIC as-is.) You can get away with coding hexadecimal digits A through F with 'A' + i
(or 'a' + i
), because those are consecutive in both ASCII and EBCDIC, but it is technically something you are getting away with rather than something guaranteed.