- [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)
- an instruction of the form delete y; and nothing else
- an instruction of the form delete x; or delete y;
- an instruction of the form y = NULL;
- it cannot be done from inside p()
- [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]
One of the differences between C++ and Pascal is that (only one answer, please)
- in Pascal it is not possible to create dangling references to the stack while in
C++ it is possible
- in Pascal it is not possible to create dangling references to the heap while in C++ it is possible
- in Pascal it is not possible to create dangling references (either to the heap or to the stack)
while in C++ it is possible
- in Pascal it is not possible to create memory leaks while in C++ it is possible
- [Pts 2]
The dynamic 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
- to point to the AR of the caller
- to store the content of the dynamic variables