Spring 2002, CSE 428: Solution of Quiz 4.1 - 7 Feb 2002
Please write your Name, Student ID, and Section at the top of the page.
By default, this quiz will be returned in Section 2 (morning section).
- [Pts 2]
In the stack-based implementation of imperative programming languages,
an activation record is (only one answer, please):
- allocated at the beginning of the execution of the program,
and never removed until the end of the execution
- allocated in the stack when it is needed,
and never removed until the end of the execution
- allocated in the heap when it is needed,
then garbage-collected when it is not necessary anymore
- allocated in the stack when it is needed, then removed
automatically when it is not necessary anymore
- [Pts 2]
The activation record associated to a function call
contains storage for (only one answer, please):
- the local variables of the caller
- the local variables of the callee (i.e. the called function)
- the dynamic variables created during
the execution of the function call
- the source code of the function
- [Pts 2]
The static link is useful in (only one answer, please):
- the implementation of languages with static scope and
nested function declarations (like Pascal)
- the implementation of languages with static scope,
even if they don't allow nested function declarations
(like C++ and Java)
- the implementation of languages with static type system (like LISP)
- the implementation of languages without dynamic variables (like Scheme)
- [Pts 2]
A dynamic variable pointed by p is
deallocated by (only one answer, please):
- an instruction of the form delete p;
- an instruction of the form p = NULL;
- an instruction of the form p = new int;
- an instruction of the form p = q;
- [Pts 2]
Which of the following fragments of code produces a memory leak
at the end (only one answer, please):
- int* p = new int; delete p; p = NULL;
- int* p = new int; int* q = new int; q = p;
- int* p = new int; int* q = p; q = NULL;
- int* p = new int; int* q = p; q = q + 1;