< previous page page_583 next page >

Page 583
The integral types in C++ are char, short, int, long, and enum. The most commonly used integral types are int and char. The char type can be used for storing small (one-byte) numeric integers or, more often, for storing character data. Character data include both printable and nonprintable characters. Nonprintable charactersthose that control the behavior of hardware devicesare expressed in C++ as escape sequences such as \n. Each character is represented internally as a nonnegative integer according to the particular character set (such as ASCII or EBCDIC) that a computer uses.
The floating point types built into the C++ language are float, double, and long double. Floating point numbers are represented in the computer with a mantissa and an exponent. This permits the use of numbers that are much larger or much smaller than those that can be represented with the integral types. Floating point representation also allows us to perform calculations on numbers with fractional parts.
Representational errors can affect the accuracy of a program's computations. When using floating point numbers, keep in mind that if two numbers are vastly different from each other in size, adding or subtracting them may give inaccurate results. Remember, also, that the computer has a limited range of numbers that it can represent. If a program tries to compute a value that is too large or too small, an error message may result when the program executes.
C++ allows the programmer to define additional data types. The Typedef statement is a simple mechanism for renaming an existing type, although the result is not truly a new data type. An enumeration type, created by listing the identifiers that make up the domain, is a new data type that is distinct from any existing type. Values of an enumeration type may be assigned, compared in relational expressions, used as case labels in a Switch statement, and returned as function values. Enumeration types are extremely useful in the writing of clear, self-documenting programs. In succeeding chapters, we look at language features that let us create even more powerful user-defined types.
Quick Check
1. The C++ simple types are divided into integral types and floating point types. What are the five integral types (ignoring the unsigned variations) and the three floating point types? (pp. 502503)
2. What is the difference between an expression and an expression statement in C++?(pp.510513)
3. Assume that the following code segment is executed on a machine that uses the ASCII character set. What is the final value of the char variable someChar? Give both its external and internal representations. (pp. 517520)
someChar = T;
someChar = someChar + 4;

 
< previous page page_583 next page >