The Type Cast Operator

You’ve already seen how enclosing a type inside a set of parentheses is used to declare the return and argument types when declaring and defining methods. It serves a different purpose when used inside expressions.

The last division operation from Program 4.5 that reads as follows introduces the type cast operator:

f2 = (float) i2 / 100;   // type cast operator

The type cast operator has the effect of converting the value of the variable i2 to type float for purposes of evaluating the expression. In no way does this operator permanently affect the value of the variable i2; it is a unary operator that behaves like other unary operators. Just as the expression -a has no permanent effect on the ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.