< previous page page_30 next page >

Page 30
and it tells you the size of the object you pass in as a parameter. For example, on line 5 the keyword int is passed into sizeof(). Using sizeof(), I was able to determine that on my computer, an int is equal to a short int, which is two bytes.
signed and unsigned
New Term: In addition, all of these types come in two varieties: signed and unsigned. Sometimes you need negative numbers, and sometimes you don't. Integers (short and long) without the word unsigned are assumed to be signed. signed integers are either negative or positive. unsigned integers are always positive.
Because you have the same number of bytes for both signed and unsigned integers, the largest number you can store in an unsigned integer is twice as big as the largest positive number you can store in a signed integer. An unsigned short integer can handle numbers from 0 to 65,535. Half the numbers represented by a signed short are negative, thus a signed short can only represent numbers from -32,768 to 32,767.
Fundamental Variable Types
Several other variable types are built into C++. They can be conveniently divided into integer variables (the type discussed so far), floating-point variables, and character variables.
Floating-point variables have values that can be expressed as fractionsthat is, they are real numbers. Character variables hold a single byte and are used for holding the 256 characters and symbols of the ASCII and extended ASCII character sets.
New Term: The ASCII character set is the set of characters standardized for use on computers. ASCII is an acronym for American Standard Code for Information Interchange. Nearly every computer operating system supports ASCII, though many support other international character sets as well.
The types of variables used in C++ programs are described in Table 3.1. This table shows the variable type, how much room this book assumes it takes in memory, and what kinds of values can be stored in these variables. The values that can be stored are determined by the size of the variable types, so check your output from Listing 3.1.
TABLE 3.1 VARIABLE TYPES
TypeSizeValues
unsigned short int2 bytes0 to 65,535
short int2 bytes-32,768 to 32,767
unsigned long int4 bytes0 to 4,294,967,295

(table continued on next page)

 
< previous page page_30 next page >

If you like this book, buy it!