Home Segments Index Top Previous Next

67: Mainline

When an expression contains two operators of equal precedence, such as multiplication and division, the C compiler handles the expression as in the following examples:

6 / 3 * 2  /* Equivalent to (6 / 3) * 2 = 4, */ 
           /* rather than to 6 / (3 * 2) = 1    */ 
6 * 3 / 2  /* Equivalent to (6 * 3) / 2 = 9, */ 
           /* rather than to 6 * (3 / 2) = 6    */ 

Thus, in C, the multiplication and division operators are said to associate from left to right. Most operators associate from left to right, but some operators do not, as you learn in the hardcopy version of this book.