A Collection of Other Mid-Term Exam Questions

[3] 6. The LISP function mapcar applies its first argument (a function) to each element of its second argument (a list), returning a list of the results. What is the result of evaluating the following function call?

(mapcar (lambda (x) (* x 2)) '(1 2 3))

[4] 7. A C++ array is declared by

int A[3][4];

Assuming a byte-addressable architecture using 32-bit (4 byte) integers and that element A[1][2] is stored at address 2400, at which address is element A[2][1] located? (Remember: C++ uses zero-based, row-major array indexing.)

At which address is element A[i][j] located? (I.e., give the addressing formula for this array in terms of variables i and j, using as many actual numbers as possible.)

4. Indicate one disadvantage of each of the following methods of storage reclamation.

a) explicit disposal

b) reference counting

c) mark-sweep garbage collection

[3] 6. Distinguish between keywords (as used in Algol), reserved words (as used in Pascal), and keywords in context (as used in FORTRAN).

[2] 7. What is the primary difference between a begin-end pair in Algol and the same construct in Pascal?

[3] 8. Describe the similarities and differences between blocks in Algol and the EQUIVALENCE statement in FORTRAN. What is the primary advantage of the former construct over the latter?

[3] 9. What is the difference between compilation and interpretation? What are the relative advantages of each method of translation?

[2] 10. How is a procedural parameter passed so as to preserve static scoping?

[3] 11. Describe three solutions to the dangling else problem.

[2] 16. Is it possible for a compiler to know the amount of space needed for executing a Fortran program? An Algol program? Why?

[1] 17. Why did the designers of Fortran and LISP include aliasing as a feature in those languages?

[12] 8. SHORT ANSWER -- Answer any four of the following questions concisely but completely in the space below, continuing on the separately provided answer pages as necessary. Label continuations clearly. Indicate clearly which four questions you are answering. The questions are worth three points each.

  1. What is the difference between compilation and interpretation? What are the relative advantages of each method of translation?
  2. Is it possible for a compiler to know the amount of space needed for executing a Fortran program? An Algol program? Why?
  3. For what principal reasons were EQUIVALENCE declarations included in FORTRAN?
  4. For what principal reasons were arrays in FORTRAN restricted to no more than three dimensions?
  5. Give some examples of features or characteristics of FORTRAN which exhibit the machine-orientation which typifies first-generation languages. (You may assume that the data-input mechanisms of the 1960's were determined by machine characteristics as well.)
  6. What is strong typing and what are its benefits?
  7. What are the relative advantages and disadvantages of explicit dynamic memory allocation/deallocation (e.g., using new and dispose in Pascal) vs. implicit handling (as in Lisp)?
  8. In the simple, nonrecursive call/return implementation for subprograms which is often used in Fortran, it is typical that no checking is done for the occurrence of a recursive call during execution. Instead, the recursive call is allowed, but later the program falls into an infinite loop. Explain the reason for this behavior in terms of the implementation model for nonrecursive subprograms.

Copyright © 2000 Jonathan Mohr