< previous page page_518 next page >

Page 518
On computers with a very limited amount of memory space, programmers sometimes use the char type to save memory when they are working with small integers. But it is far more common to use char variables to store character data, such as the character A or e or +:
char someChar;
.
.
.
someChar = A;
A natural question to ask is, How does the computer know the difference between integer data and character data when the data is sitting in a memory cell? The answer is, The computer can't tell the difference! To explain this surprising fact, we have to look more closely at how character data is stored in a computer.
Character Sets
Each computer uses a particular character set, the set of all possible characters with which it is capable of working. There are two character sets widely in use today: the ASCII character set and the EBCDIC character set. ASCII is used by virtually all personal computers and minicomputers, and EBCDIC is found primarily on IBM mainframe computers. ASCII consists of 128 different characters, and EBCDIC has 256 characters. Appendix E shows the characters that are available in these two character sets.
Each character has an external representationthe way it looks on an I/O device like a printerand an internal representationthe way it is stored inside the computer's memory unit. If you use the char constant A in a C++ program, its external representation is the letter A. That is, if you print it out you see an A, as you would expect. Its internal representation, though, is an integer value. The 128 ASCII characters have internal representations 0 through 127; the EBCDIC characters, 0 through 255. For example, the ASCII table in Appendix E shows that the character A has internal representation 65, and the character b has internal representation 98.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
External Representation The printable (character) form of a data value.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Internal Representation The form in which a data value is stored inside the memory unit.
Let's look again at the statement
someChar = A;

 
< previous page page_518 next page >