Conversion and Casts
Automatic conversions:
- e.g.. if i is an int and f is a float, in the expression i + f, the operand i gets promoted to a float and expression i + f as a whole has type float.
- similarly, if d is double and i is int, expression statement d = i causes the value of i to be converted to a double and then assigned to d, and double is the type of the expression as a whole. (what if i = d ?)
Explicit type conversion
- Cast (type_name) variable name/expression
e.g.
(long) ('A' + 1.0)
float x;
x = (float) ((int) y + 1);