Electrical and Computer Engineering
41 of 48
UAH
CPE 112
Type Casting
(Explicit Coercion)
•A C++ cast operation consists of a data type name and then, within parentheses, the expression to be converted:
–someFloat = float (3 * someInt + 2);
–someInt = int (5.2 / someFloat – anotherFloat);
•Countless errors have resulted from unintentional mixing of types.
•It’s possible to mix data types within an expression.