Chapter 9
Characters
Up to this point, weâve mostly used variables of type int, float, and double. In this chapter, weâll focus on the char type. To show you how to work characters, we assume that the underlying character set relies on the most popular set, the 8-bit ASCII (American Standard Code for Information Interchange) code. As you can see in Appendix B, ordinary characters, such as letters and digits, are represented by integers from 0 to 255.
char Type
Since a character in the ASCII set is represented by an integer between 0 and 255, we can use the char type to store its value. When a character is stored into a variable, it is the characterâs ASCII value that is actually stored. In the following example,
char ch;
ch = 'c';
the ...
Get C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.