Q4. What is the impact of type modifiers on base data types? Support your answer with examples for each data type.
Ans. We use a modifier to alter the meaning of the base type to fit various situations more precisely.
The list of modifiers is given below:
- Integer Type Modifiers
By using different number of bytes to store values, C++ offers three types of integers: short, int and long that can represent up to three different sizes. Each comes in both signed and unsigned versions. That gives you a choice of six different integer types.
|Type||Approximate Size (in bytes)||Minimal Range|
|Short||2||-32768 to 32767|
|unsigned short||2||0 to 65,535|
|signed short||2||Same as short|
|Int||2||-32768 to 32767|
|unsigned int||2||0 to 65,535|
|signed int||2||Same as int|
|Long||4||-2,147,483,648 to ,147,483,647|
|unsigned long||4||0 to 5,294,967,295|
|signed long||4||Same as long|
- Character Type Modifiers
The char type can also be signed and unsigned. Unlike int, char is neither signed nor unsigned by default. The choice is left to the C++ implementation in order to allow the implementer to best fit the type to the hardware properties. However, these distinctions are particularly important if you are using char as a numeric type. The unsigned char represents the range 0 to 255 and signed char represents the range -128 to 127.
- Floating-point Type Modifiers
C++ has three floating-point types: float, double and long double. These types are described in terms of the number of significant figures they can represent and the minimum allowable range of exponents.
Type float occupies 4 bytes of memory. Type double occupies 8 bytes, twice as much memory as type float and stores floating-point numbers with much larger range and precision. Floating-point type Long double occupies 10 bytes and has only slightly greater range and precision than type double.
|Types||Approximate Size (in bytes)||Minimal Range||Digits of Precision|
|Float||4||3.4 x 10-38 to 3.4 X 1038 -1||7|
|double||8||1.7 X 10-308 to 1.7 X 10308 -1||15|
|long double||10||3.4 X 10 -4932 to 1.1 X 10 4932 -1||19|