A char in the C programming language is a fixed-size byte entity designed specifically to be large enough to store a character value from an encoding such as ASCII.
But to what extent are the integer values relating to ASCII encoding interchangeable with the char characters? Is there any way to refer to ‘A’ as 65 (decimal)?
getchar() returns an integer – presumably this relates directly to such values? Also, if I am not mistaken, it is possible in certain contexts to increment chars … such that (roughly speaking) ‘?’+1 == ‘@’.
Or is such encoding not guaranteed to be ASCII? Does it depend entirely upon the particular environment? Is such manipulation of chars impractical or impossible in C?
Edit: Relevant: C comparison char and int
In fact, you can’t do anything else.
charis just an integral type, and if you writethen (assuming ASCII),
chwill merely hold the integer value65– presenting it to the user is a different problem.No, it isn’t. C doesn’t rely on any specific character encoding.
Yes, pretty much.
No, you just have to be careful and know the standard quite well – then you’ll be safe.