Data Type Conversions
Chapter 4, “Data Types and Expressions,” briefly addressed the fact that sometimes the system implicitly makes conversions when expressions are evaluated. You examined a case with the data types float
and int
. You saw how an operation that involves a float
and an int
was carried out as a floating-point operation, with the integer data item automatically converted to a floating point.
You also saw how the type cast operator can be used to explicitly dictate a conversion. So given that total
and n
are both integer variables
average = (float) total / n;
the value of the variable total
is converted to type float
before the operation is performed, thereby guaranteeing that the division will be carried out as a floating-point ...
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.