6.6 Data Types


6.6 Data Types

Data comes in various types: numerical, alphabetical, Boolean, and so on. The total number of data types is unlimited since it's possible for programmers to define their own kinds of data. But C++ provides a number of fundamental types that tend to be used by most programs. The following subsections list some of the most common data types encountered in C++.

Tip 

Remember, C++ is case sensitive. Thus, such words as "int," "INT," and "Int" are treated as separate items.

Tip 

In C++ a keyword is a reserved word. There are certain reserved words in C++, some of which are listed in Appendix E, and programmers can only use those words to mean one thing, as we shall see.

6.6.1 Integers

Integers are whole numbers like 5, 0 and 7. They do not have fractional components, such as 5.5, 7.3, 3.2. C++ represents integers with the keyword int. Each time int is included in a C++ program, it means an integer value. Later sections demonstrate how integer data types are used.

6.6.2 Floats

Float means floating-point number and is used to define numerical data, which may or may not include a fractional value, and thus may or may not have a decimal point. Floats require more memory than integers, and are implemented in C++ using the float keyword.

6.6.3 Boolean

Booleans are numerical data whose value can be either 1 or 0, corresponding to true or false, respectively. Booleans are indicated in C++ by the keyword bool.

6.6.4 Char

Characters are letters and other symbols that can appear on a keyboard, such as "a," "b," and "@." Ultimately, each character corresponds to a number, but the character data type stores data in the context of a character rather than a number. The keyword for a character in C++ is char.




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net