1. After the following code runs, there will be pointers to the heap from for(in
ID: 3726767 • Letter: 1
Question
1. After the following code runs, there will be pointers to the heap from
for(int i=0;i
allocs[i]=malloc(i*2+128);
if(i>0)
*(void**)(allocs[i])=allocs[i-1];
}
(A) .data or globals
(B) heap
(C) stack
(D) nowhere
(E) .data or global, heap and stack
2.Where will there be pointers to the heap when gc() is called in the following code?
void* recursive_allocations(int i) {
void* ptr = malloc(i*100+128);
if (i==0) return ptr;
void *ptr2 = recursive_allocations(i-1);
if(i==50) {
gc();
printf("Recursive1: at depth 50, %zu, free %d, inuse %d ",heap_size(),free_chunks(),inuse_chunks());
}
return ptr;
}
(A) .data or globals
(B) heap
(C) stack
(D) nowhere
(E) .data or global, heap and stack
Explanation / Answer
[1] stack memory is where local variables get stored/constructed
[C] Stack
[2] Garbage Collection runs on the heap memory to free the memory
[B] heap
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.