Spring 2002, CSE 428: Solution of Quiz 3.1 - 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 effect of a statement (or command) in an imperative language (only one answer, please)
    1. it computes the type of an expression
    2. it transforms 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 {(a, 3), (b, 4)}. Is there a state sigma2 such that
       sigma1 |-  c = a + b  ==>  sigma2
    
    (that is, where the assignment c = a + b transforms state sigma1 to sigma2)? If so, write sigma2 explicitly as a set of pairs.

    {(a, 3), (b, 4), (c, 7)}

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

  4. [Pts 2] What is the lifetime of a global 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 execution of the line where it is declared
    4. The execution of the procedure/function where it is declared