Spring 2002, CSE 428: Solution of Quiz 3.4 - 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 1 (afternoon section).

  1. [Pts 2] What is the result of the evaluation of an assignment (only one answer, please)
    1. it changes the type mapping
    2. it changes the state
    3. it checks that the program is statically correct
    4. it checks that the program is dynamically correct

  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, 4), (y, 5)}. Is there a state sigma2 such that

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

    {(x, 4), (y, 5), (z, 9)}

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

  4. [Pts 2] When is a dynamic variable allocated (only one answer please)
    1. When a variable of type pointer is declared (like int* p;)
    2. When a variable of type pointer is assigned (like p = q;, where q is another pointer)
    3. When an instruction new is executed on variable of type pointer (like p = new int;)
    4. When a variable of type pointer is dereferenced (like *p = 5;)