ICS 313-03 (021)
Quiz # 3
18 Nov, 2002
Describe a situation in which the add operator in a programming language would not be associative.
Consider the integer expression
A + B + C
Suppose the values of
are 20,000, 25,000, and
Further suppose that the machine has a maximum integer value of 32,767.
the first addition is computed first, it will result in overflow.
If the second addition is done first, the
whole expression can be correctly computed.
Assume the following rules of associativity and precedence for expression:
*, /, not
+, -, &, mod
=, /=, <, <=, >=, >
left to right
Show the order of evaluation of the following two expressions by parenthesizing all subexpressions
and placing superscript on the right parenthesis to indicate order.
a *(b - 1) / c
c = d
( ( ( a * ( b - 1 )
/ c )
mod d )
(( - a )
or (( c = d )
and e )