go to previous page   go to home page   go to next page hear noise highlighting

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:

If both operands of an arithmetic operator are integers, then the operation is an integer operation. If any operand is floating point, then the operation is floating point.

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

go to previous page   go to home page   go to next page