< previous page page_66 next page >

Page 66
ExpressionValue
3 + 69
3.4 - 6.1-2.7
2 * 36
8 / 24
8.0 / 2.04.0
8 / 81
8 / 90
8 / 71
8 % 80
8 % 98
8 % 71
0 % 70
5 % 2.3error (both operands must be integers)

Be careful with division and modulus. The expressions 7.0 / 0.0, 7 / 0, and 7 % 0 all produce errors. The computer cannot divide by zero.
Because variables are allowed in expressions, the following are valid assignments:
alpha = num + 6;
alpha = num / 2;
num = alpha * 2;
num = 6 % alpha;
alpha = alpha + 1;
num = num + alpha;
Notice that the same variable can appear on both sides of the assignment operator. In the case of
num = num + alpha;
the value in num and the value in alpha are added together, then the sum of the two values is stored into num, replacing the previous value stored there. This example shows the difference between mathematical equality and assignment. The mathematical equality
0066-03.gif
is true only when alpha equals zero. The assignment statement

 
< previous page page_66 next page >