Spring 2002, CSE 428: Solution of Quiz 4.4 - 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 1 (afternoon section).
  1. [Pts 2] Is it possible to determine at compile time the part of the stack which will be used to run a certain program P? (only one answer, please)
    1. yes, by static analysis: the types determine the size of the variables
    2. yes: the target language determines the size of the variables
    3. no, because it depends on run-time information, and different executions of P can use different portions of the stack
    4. no, but all executions of P will use the same portion of the stack

  2. [Pts 2] Is it possible to have two activations records present at the same time for one function f? (only one answer, please)
    1. no, it would be useless: the AR for f contains all the memory necessary to run f
    2. no, it would be confusing: we would not know which copy of the AR to use
    3. yes, it happens for instance if we have two subsequent calls f(); f();
    4. yes, it happens for instance if f is recursive

  3. [Pts 2] The dynamic link in the activation record of f is used to:
    1. determine the position of the activation record of the caller
    2. determine the continuation in the code of the program after f returns
    3. determine the environment for the non-local variables of f, if the language has static scope
    4. determine the environment for the local variables of f

  4. [Pts 2] Assume p is a global pointer to int and consider the following declaration
       void f(int x){
          p = &x;
       }
    
    The execution of the code int* q = new int; *q = 5; f(*q); leaves (only one answer, please):
    1. a memory leak
    2. a dangling pointer to the heap
    3. a dangling pointer to the stack
    4. noting, because the variable pointed by q is still allocated

  5. [Pts 2] What is the value printed by the following fragment of code?
      int* p = new int;
      *p = 1; 
      int* q = p; 
      int* r = p; 
      *q = *q + 1;
      *r = *r + 1;
      cout << *p;
    
      3