# Thursday September 14, 1995

Handouts (available on-line): none

Topics Covered:

• 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 program and 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). Program and sample run.
• 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.
• Rules for forming integer expressions.
• Here's a copy of the operator precedence and associativity table.
• A program that uses expressions in unexpected ways and a sample run.
• 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.
• Rules for naming variables.
• A program that uses a simple for loop to print a message 10 times. Program and sample run.
• A second version of the program that prints the message with numbers. Program and sample run.