1. Numeric Data Types( 9 kinds )
? ? Name Synonymy Strorage Size
? ? short ? short int? 16-bit signed
? ? unsigned short? unsigned short int? 16-bit unsigned
? ? int --- 32-bit signed
? ? unsigned int? unsigned 32-bit unsigned
? ? long long int? 32-bit signed
? ? unsigned long? unsigned long int? 32-bit unsigned
? ? float --- 32-bit IEEE 754
? ? double --- 64-bit IEEE 754
? ? long double? --- 80-bit
?
2. Numeric Type Convertions
- if one of the operands is long double, the other is converted into long double;
- Otherwise, if one of the operands is double, the other is converted into double;
- Otherwise, if one of the operands is float, the other is converted into float;
- Otherwise, if one of the operands is unsigned long, the other is converted into unsigned long;
- Otherwise, if one of the operands is long, the other is converted into long;
- Otherwise, if one of the operands is unsigned int, the other is converted into unsigned int;
- Otherwise, both operands are converted into int.
? ? ? Casting
Operator :
static_cast<type>(value)
3. ?Character Data Type
? ? ?Name StorageSize
? ? ?char?
? ? ? ? ? ? ? ? ? ? ? ?1 character?
4. Casting between char and Numeric Types
-
char can be cast into any numberic type, and vice versa.
- When an integer is cast into a char, only its lower 8 bits of data are used.
- When a floating-point value is cast into a char, the floating-point vlaue is first cast into an int, which is then cast into a char.
5.
bool Data Type
? ? Name StorageSize
? ? bool
? ? ? ? ? ? ? ? ? ? ? ?1 character?
? ? In C++, any
nonzero value evaluates
true and
zero value evaluates
false.
?
6. widening a type v.s. narrowing a type?
-
widening a type : casting a variable of a type with a small range to a variable of a type with a larger range.
-
narrowing a type : casting a variable of a type with a large range to a variable of a type with a smaller range.?
- Narrowing a type may lose precision.
7.
switch ( switch-
expression )
? ? In C++, a
char or
bool value is treated as an integral. So, this type of value used in a switch statement as a switch expression or case value.
?