< previous page page_55 next page >

Page 55
the C++ compiler takes this to mean the decimal number 13. If you aren't familiar with the octal number system, don't worry about why an octal 15 is the same as a decimal 13. The important thing to remember is not to start a decimal integer value with a zero (unless you want the number 0, which is the same in both octal and decimal). In Chapter 10, we discuss the various integral types in more detail.
More About the char Type
We have seen that char is the smallest data type for representing integer values. A char value occupies less memory space than an int value, so programmers sometimes use the char data type to save memory in programs that use small integer values. But there is another, far more important use of the char type: to describe data consisting of one alphanumeric charactera letter, a digit, or a special symbol:
A   a   8   2   +   -   $     ?    *      
Each machine uses a particular character set, the set of alphanumeric characters it can represent. (See Appendix E for some sample character sets.) Notice that each character is enclosed in single quotes (apostrophes). The C++ compiler needs the quotes to differentiate between the character data 8 and the integer value 8 because the two are stored differently inside the machine. Notice also that the blank, , is a valid character.
You wouldn't want to add the character A to the character B or subtract the character 3 from the character 8, but you might want to compare character values. Each character set has a collating sequence, a predefined ordering of all the characters. Although this sequence varies from one character set to another, A always compares less than B, B less than C, and so forth. And 1 compares less than 2, 2 less than 3, and so on. None of the identifiers in the Payroll program is of type char.
Floating Point Types
Floating point types (or floating types), the second major category of simple types in C++, are used to represent real numbers. Floating point numbers have an integer part and a fractional part, with a decimal point in between. Either the integer part or the fractional part, but not both, may be missing. Here are some examples:
18.0   127.54   0.57   4.   193145.8523   .8
Starting 0.57 with a 0 does not make it an octal number. It is only with integer values that a leading 0 indicates an octal number.
Just as the integral types in C++ come in different sizes (char, short, int, and long), so do the floating point types. In increasing order of size, the floating point types are float, double (meaning double precision), and long

 
< previous page page_55 next page >