Spring 2002, CSE 428: Solution of Quiz 4.1 - 7 Feb 2002


Please write your Name, Student ID, and Section at the top of the page.
By default, this quiz will be returned in Section 2 (morning section).
  1. [Pts 2] In the stack-based implementation of imperative programming languages, an activation record is (only one answer, please):
    1. allocated at the beginning of the execution of the program, and never removed until the end of the execution
    2. allocated in the stack when it is needed, and never removed until the end of the execution
    3. allocated in the heap when it is needed, then garbage-collected when it is not necessary anymore
    4. allocated in the stack when it is needed, then removed automatically when it is not necessary anymore

  2. [Pts 2] The activation record associated to a function call contains storage for (only one answer, please):
    1. the local variables of the caller
    2. the local variables of the callee (i.e. the called function)
    3. the dynamic variables created during the execution of the function call
    4. the source code of the function

  3. [Pts 2] The static link is useful in (only one answer, please):
    1. the implementation of languages with static scope and nested function declarations (like Pascal)
    2. the implementation of languages with static scope, even if they don't allow nested function declarations (like C++ and Java)
    3. the implementation of languages with static type system (like LISP)
    4. the implementation of languages without dynamic variables (like Scheme)

  4. [Pts 2] A dynamic variable pointed by p is deallocated by (only one answer, please):
    1. an instruction of the form delete p;
    2. an instruction of the form p = NULL;
    3. an instruction of the form p = new int;
    4. an instruction of the form p = q;

  5. [Pts 2] Which of the following fragments of code produces a memory leak at the end (only one answer, please):
    1. int* p = new int; delete p; p = NULL;
    2. int* p = new int; int* q = new int; q = p;
    3. int* p = new int; int* q = p; q = NULL;
    4. int* p = new int; int* q = p; q = q + 1;