< Previous | Contents | Next >

Understanding Type Modifiers

You can use modifiers to alter a type. short is a modifier that can reduce the total number of values a variable can hold. long is a modifier that can increase the total number of values a variable can hold. short may decrease the storage space required for a variable while long may increase it. short and long can modify int. long can also modify double.

signed and unsigned are modifiers that work only with integer types. signed means that a variable can store both positive and negative values, while unsigned means that a variable can store only positive values. Neither signed nor unsigned change the total number of values a variable can hold; they only change the range of values. signed is the default for integer types.

Okay, confused with all of your type options? Well, dont be. Table 1.1 summarizes commonly used types with some modifiers thrown in. The table also provides a range of values for each.


Tra p

image

The range of values listed is based on my compiler. Yours might be different. Check your compiler’s documentation.

image


Hi n t

image

For brevity’s sake, short int can be written as just short and long int can be written as just

long.

image

image

256 character values

true or false

38 (seven significant digits)

308 (15 significant digits)

308 (15 significant digits)

3.4E þ/

1.7E þ/

1.7E þ/

32,768 to 32,767

0 to 65,535

2,147,483,648 to 2,147,483,647

0 to 4,294,967,295

2,147,483,648 to 2,147,483,647

0 to 4,294,967,295

short int

unsigned short int int

unsigned int long int

unsigned long int float

double

long double char

bool

Table 1.1 Commonly Used Types

Type Values

Declaring and Initializing Variables 19