ICS 313-03 (021)
Quiz # 3
Weight
4%
18 Nov, 2002
Q. 1
[5 points]:
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
A
,
B
, and
C
are 20,000, 25,000, and
-20,000, respectively.
Further suppose that the machine has a maximum integer value of 32,767.
If
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.
Q. 2
[5 points]:
Assume the following rules of associativity and precedence for expression:
Precedence:
Highest
*, /, not
+, -, &, mod
-
(unary)
=, /=, <, <=, >=, >
and
Lowest
or, xor
Associativity:
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.
a *(b - 1) / c
mod
d
b.
–a
or
c = d
and
e
a.
( ( ( a * ( b - 1 )
1
)
2
/ c )
3
mod d )
4
b.
(( - a )
1
or (( c = d )
2
and e )
3
)
4
ID: ___________
Name: _____________________
This
preview
has intentionally blurred sections.
Sign up to view the full version.
Q. 3
[5 points]:
Rewrite the following code segment using a multiple selection statement in C or Java:
This is the end of the preview.
Sign up
to
access the rest of the document.
- Spring '07
- alvi
- Addition, following code segment, multiple selection statement, maximum integer value, logical looping construct
-
Click to edit the document details