| As you've seen, C++ allows you to specify a number of qualifiers for variable declarations. Qualifiers may be thought of as adjectives that describe the type that follows . Table 5-2 summarizes the various qualifiers; they are explained in detail in the following sections. Table 5-2. Qualifiers and simple types | Special | Constant | Storage class | Size | Sign | Type | | volatile | const | register | long | signed | int | | <blank> | <blank> | static | short | unsigned | float | | | | extern | double | <blank> | char | | | | auto | <blank> | | wchar_t | | | | <blank> | | | <blank> | 5.10.1 Special The volatile keyword is used for specialized programming such as I/O drivers and shared memory applications. It is an advanced modifier whose use is far beyond the scope of this book. - volatile
-
Indicates a special variable whose value may change at any time - <blank>
-
Normal variable 5.10.2 Constant The const keyword indicates a value that cannot be changed. - const
-
Indicates that this is a declaration of constant data - <blank>
-
Normal variable 5.10.3 Storage Class The class of a variable is discussed in detail in Chapter 9. A brief description of the various classes follows: - register
-
This indicates a frequently used variable that should be kept in a machine register. See Chapter 17. - static
-
The meaning of this word depends on the context. This keyword is described in Chapter 9 and Chapter 23. - extern
-
The variable is defined in another file. See Chapter 23 for more information. - auto
-
A variable allocated from the stack. This keyword is hardly ever used. - <blank>
-
Indicates that the default storage class is selected. For variables declared outside a function, this makes the variable global. Variables inside a function are declared auto . 5.10.4 Size The size qualifier allows you to select the most efficient size for the variable. - long
-
Indicates a larger than normal number. - short
-
Indicates a smaller than normal integer. - double
-
Indicates a double-size floating-point number. - <blank>
-
Indicates a normal-size number. 5.10.5 Sign Numbers can be signed or unsigned . This qualifier applies only to char and int types. Floating-point numbers are always signed. The default is signed for int and undefined for characters . 5.10.6 Type This specifies the type of the variable. Simple types include: - int
-
Integer. - float
-
Floating-point number. - char
-
Single character, but can also be used for a very short integer. - wchar_t
-
Single wide character. Can also be used for a short integer, but most people don't because the other integer types are more appropriate to use. |