CS 330 Exam #3 Review Questions

  1. Describe the contents of a typical activation record.

  2. What's the difference between a static link pointer and a dynamic link point, as related to subprogram control?

  3. Given the following graphic that describes a particular series of activations of subprograms within some program, describe how variable accesses are resolved for this statement:
  4. Explain what a thunk is and what it does.

  5. For the following function, consider that the parameters are passed by name. What problem can arise with this example?

  6. When local referencing environments are deleted between subprogram activations, using a central stack as in C/C++, it sometimes appears as if values are retained. For example, if procedure Sub has a local variable X and Sub assigns the value 5 to X on the first call, then on a second call, if X is (inadvertently) referenced before it is assigned a new value, sometimes X still has its old value 5. However, in the same program, a third call on Sub may find X has not retained its old value from the second call. Explain this apparent anomaly. In what circumstances could an activation that references an uninitialized variable find that that variable still had a value assigned on a previous call? In what circumstances would it not have its previously assigned value (but may have some other value entirely unrelated to that variable)?

  7. Explain why it is impossible in a language with only parameters transmitted by value or name (such as Algol) to write a subprogram Swap of two parameters that simply swaps the values of its two parameters (which must be simple or subscripted variables). For example, Swap(X,Y) should return with X having the original value of Y and Y having the original value of X. For the purposes of this question, consider that the parameter types are integers.

  8. What are the advantages and disadvantages of requiring that the programmer be entirely responsible for managing memory?

  9. What are the three phases of storage management?

  10. Give an example in code (either Java or C++) of causing the program stack to run out of space.

  11. Give an example in code (either Java or C++) of causing the program heap to run out of space.

  12. Give an example that illustrates the problem of memory fragmentation.

  13. Describe the mark-sweep algorithm (fixed-size blocks) for garbage collection.

  14. Give an example of a hardware generated exception, and an example of a software generated exception.

  15. What are the two sources of exceptions?

  16. Write Java code that will generate a DivideByZero exception when attempting to execute the following statement:

  17. What is the main problem with exception range checking subscripts with each array reference?