Spring 2001, CSE 428: Quiz 5.3 - 22 Feb 2001


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). If you want to get it back in the morning section, please write "Section 2" at the top of the page.
  1. [Pts 2]

    Consider the following fragment of code

       void p(){
          int* x = new int;
          int* y = x;
          c;  // c here represents an arbitrary command
       }
    
       void main(){
          p();
          ...
       }
    
    The deallocation of the dynamic variable created with int* x = new int; can be done by replacing c; with (only one answer, please)

    1. an instruction of the form delete x; and nothing else
    2. an instruction of the form delete x; or delete y;
    3. an instruction of the form x = NULL;
    4. no need for explicit deallocation: it will be done automatically when the call to p() returns

  2. [Pts 2]

    In the previous code, if we replace c; with x = NULL; , after p() returns we will have (only one answer, please)

    1. a dangling reference
    2. a memory leak
    3. a "segmentation fault" error
    4. none of the above

  3. [Pts 2]

    In the previous code, if we replace c; with delete x; , after p() returns we will have (only one answer, please)

    1. a dangling reference
    2. a memory leak
    3. both a dangling reference and a memory leak
    4. none of the above

  4. [Pts 2]

    The destructor method of a class C is called automatically when (only one answer, please)

    1. an object x created with a declaration of the form C x; goes out of scope
    2. an object x created with a declaration of the form C* x; is deleted
    3. in both the cases above
    4. in neither the cases above

  5. [Pts 2]

    The static link is used (only one answer, please)

    1. in languages with static scope, to find the bindings for the non-local variables at run time
    2. in languages with dynamic scope, to find the bindings for the non-local variables at run time
    3. in languages with static type checking, to find the types of the static variables
    4. to store the content of the static variables