]
>
Type Conversions
2.6 Type Conversions
-
Automatically, by Definition of Operators
-
- Mixed mode expressions.
- Integral promotion: char, short, and enumeration into int.
- Upward promotion along the list: int, unsigned int, long,
unsigned long, float, double, long double.
- Assignment instructions: into type of receiver.
-
By Casting
-
- Prefix notation ‘( type ) value’
- Function-call notation ‘type (value)’
Note: Casting might not be safe, e.g., wide to narrow data type
The following table shows the integer representation of characters.
| |
|
|
|
|
|
|
|
|
|
|
| | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|
|
|
|
|
|
|
|
|
|
| | 1 | | \t | \n | | | | | |
|
|
|
|
|
|
|
|
|
|
| | 3 | | | | ! | " | # | $ | % | & | ' |
|
|
|
|
|
|
|
|
|
|
| | 4 | ( | ) | * | + | , | - | . | / | 0 | 1 |
|
|
|
|
|
|
|
|
|
|
| | 5 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; |
|
|
|
|
|
|
|
|
|
|
| | 6 | < | = | > | ? | @ | A | B | C | D | E |
|
|
|
|
|
|
|
|
|
|
| | 7 | F | G | H | I | J | K | L | M | N | O |
|
|
|
|
|
|
|
|
|
|
| | 8 | P | Q | R | S | T | U | V | W | X | Y |
|
|
|
|
|
|
|
|
|
|
| | 9 | Z | [ | \ | ] | ^ | _ | ` | a | b | c |
|
|
|
|
|
|
|
|
|
|
| | 10 | d | e | f | g | h | i | j | k | l | m |
|
|
|
|
|
|
|
|
|
|
| | 11 | n | o | p | q | r | s | t | u | v | w |
|
|
|
|
|
|
|
|
|
|
| | 12 | x | y | z | { | | | } | ~ | | | |
|
|
|
|
|
|
|
|
|
|
| | |
|