Spring 2002, CSE 428: Solution of Quiz 3.2 - 31 January 2002


Please write your Name and Student ID,at the top of the page.
By default, this quiz will be returned in Section 2 (morning section).

  1. [Pts 2] What is the result of the evaluation of an assignment x := e (only one answer, please)
    1. it changes the value of the expression e
    2. it changes the value associated to x
    3. it checks that the value of x and the value of e are the same
    4. it returns a new environment

  2. [Pts 3] Note: in this exercise the notion of state is the one described in Chapter 3, namely an association between names and values.

    Let sigma1 be the state {(x, 2), (y, 3)}. Is there a state sigma2 such that

       sigma1 |-  x = x + y ==>  sigma2
    
    (that is, where the assignment x = x + y transforms state sigma1 to sigma2)? If so, write sigma2 explicitly as a set of pairs.

    {(x, 5), (y, 3)}

  3. [Pts 3] Consider the following declaration in C++, where y is a global variable:
      void p(int & x){
          x = x + 1;
          y = y + 2;
       }
    
    What is the value printed by the following fragment of code, given the above declaration?
       y = 1;
       p(y);
       cout << y; 
    
    4

  4. [Pts 2] What is the lifetime of a dynamic variable (only one answer please)
    1. The execution of the part of the code where it is used
    2. The entire execution of the program
    3. The time between the new and the delete instruction (or until it is garbage-collected)
    4. The execution of the procedure/function where it is declared