- [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)
- an instruction of the form delete x; and nothing else
- an instruction of the form delete x; or delete y;
- an instruction of the form x = NULL;
- no need for explicit deallocation: it will be done automatically when the call to p() returns
- [Pts 2]
In the previous code, if we replace c; with x = NULL; , after p() returns we will have (only one answer, please)
- a dangling reference
- a memory leak
- a "segmentation fault" error
- none of the above
- [Pts 2]
In the previous code, if we replace c; with delete x; , after p() returns we will have (only one answer, please)
- a dangling reference
- a memory leak
- both a dangling reference and a memory leak
- none of the above
- [Pts 2]
The destructor method of a class C is called automatically when (only one answer, please)
- an object x created with a declaration of the form C x; goes out of scope
- an object x created with a declaration of the form C* x; is deleted
- in both the cases above
- in neither the cases above
- [Pts 2]
The static link is used (only one answer, please)
- in languages with static scope, to find the bindings for the non-local variables at run time
- in languages with dynamic scope, to find the bindings for the non-local variables at run time
- in languages with static type checking, to find the types of the static variables
- to store the content of the static variables