Spring 2001, CSE 428: Quiz 5.4 - 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

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

    1. an instruction of the form delete y; and nothing else
    2. an instruction of the form delete x; or delete y;
    3. an instruction of the form y = NULL;
    4. it cannot be done from inside p()

  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]

    One of the differences between C++ and Pascal is that (only one answer, please)

    1. in Pascal it is not possible to create dangling references to the stack while in C++ it is possible
    2. in Pascal it is not possible to create dangling references to the heap while in C++ it is possible
    3. in Pascal it is not possible to create dangling references (either to the heap or to the stack) while in C++ it is possible
    4. in Pascal it is not possible to create memory leaks while in C++ it is possible

  5. [Pts 2]

    The dynamic 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. to point to the AR of the caller
    4. to store the content of the dynamic variables