Mixing types can lead to strange results.
Generally, if a binary operator is used on both
an integer and a double, the integer is converted
to a double and the result is a double. So, dividing
a 9.0 by 4 gives the double value 2.25. Dividing 9 by 4
gives the integer value 2. Here's a
sample run that demonstrates
division and mixing types.
The modulo operator, %, can be used to calculate
the remainder of an integer divided by another integer.
(E.g., 7 % 4 is 3.) We can use the modulo operator
to modify the program that converts centimeters to
feet and inches (as integers).
Discussed operator precedence and associativity (important).
Multiplication and division have higher precedence than addition
and subtraction. These four operators also associate left to right.
Assignment is an operator too; it associates right to left.
Expressions that change the value of one or more variables
are said to have a side effect. For example, an expression that
uses the assignment operator has a side effect.
It is possible to write an expression with several side effects.
Since these side effects can be unpredictable, such expressions
should be avoided.
Here's a program with unpredictable
side-effects. The sample runs
on different machines give different results. This is because C
does not explicitly say if the left subexpression or the right
subexpression of a binary operator should be evaluated first.