Expressions and Arithmetic Operators

Read this chapter, which discusses arithmetic operations in greater detail along with solving expressions with mixed data types.

11. Mixed Floating Point and Integer Expressions


Answer:

You look at the operands of the operator.

Mixed Floating Point and Integer Expressions

But what if one operand is an integer and the other is a floating point? The rule is:


For example, the following are integer operations (assume that a and b are int variables):

12 * b
a - 2
56%a

Each operation in the following expressions is a floating point operation (assume that a and b are int variables, and that x and y are floating point variables):

x * b
(a - 2.0)
56*y

In complicated expressions, an operand of a particular operator might be a subexpression. But the rule still applies: if one or both operands is a floating point type then the operation is floating point. In the following, each / operation is floating point:

(12.0 * 31) / 12
(a - 2.0) / b
56*x/3

In that last example, the 56*x is a floating point subexpression that becomes an operand for the division operator. (Because * and / have equal precedence, the evaluation is done from left to right.)

Question 11:

What type (integer or floating point) of operator is the / in the following:

    (12 + 0.0) / 7