Midterm 2, CSCI 3155
October 28th, 2003
You have 70 minutes to answer these questions. Please read all
questions before you start. This is a closed-book exam. Please
remember that you are bound by the CU honor code.
- Answer these questions about operator precedence and operation
evaluation order:
- [10 points] Describe the concepts of operator precedence and operand
evaluation order.
- [10 points] Demonstrate the difference between these two concepts
using an example .
- Answer these questions about subtyping and parameter passing mechanisms
- [10 points] Give the most general subtyping rule for when one
subrange type is a subtype of another subrange type. Describe why your
rule makes sense.
- [5 points] Explain the term widening conversion.
Give an example assignment statement such that the assignment requires a
widening conversion.
- [5 points] Explain the term narrowing conversion.
Give an example assignment statement such that the assignment requires a
narrowing conversion.
- [5 points] Explain the difference between in and inout
modes of parameter passing.
- [5 points] Consider a routine that expects an argument of type [1
TO 100] and uses the in mode of parameter passing. What is the
maximal set of types of arguments that I can pass to this routine?
Explain.
- [5 points] Consider a routine that expects an argument of type [1
TO 100] and uses the inout mode of parameter passing. What is
the maximal set of types of arguments that I can pass to this routine?
Explain.
- The ability to pass procedures as arguments and return procedures as
results is very powerful. In your answer to this question, you must
write your code in MYSTERY
syntax.
- [15 points] Write a function, aggregate. Aggregate takes two arguments,
an array of integers and a procedure, and returns the sum of the result of
applying the procedure to all elements of the array. For this question,
you can assume that the array argument is of type ARRAY [1 TO 5] OF INTEGER.
Thus, if the procedure argument is called p and the array argument is
called a, the outcome of your function should be: p(a[1]) + p(a[2]) +
p(a[3]) + p(a[4]) + p(a[5]).
- [10 points] Give example code that calls aggregate.
- Answer these questions about pointers and memory management:
- [8 points] What is a dangling pointer? Illustrate with an
example.
- [6 points] Does garbage collection eliminate dangling pointers? Explain.
- [6 points] Does garbage collection free up all objects that a
program does not need? Explain.