521 views
2 votes
2 votes
Consider the code snippets:

i)

void foo()
{
    while(1)
    int *i= new int;
}

 

ii)

void foo()
{
    foo();
}

 

Choose the ocrrect statements:

A. Both shows stack overflow

B. Both shows heap overflow.

C. i shows stack overflow while ii shows heap overflow

D. i shows heap overflow while ii shows stack overflow

1 Answer

0 votes
0 votes
Stack overflow is for number of elements , where heap overflow going beyond range.

Stack overflow- Say An array can store 3 elements, and we want to put 4 elements in it, then it is stack overflow.

Heap overflow-If there are elements write beyond range, then it is heap overflow.

Ans B) Both are heap overflow.

PS-[Though we think there are unlimited space in heap, but actually no computer device can store unlimited space.So, heap overflow actually happens when there is infinite calling of function.]

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
3
sh!va asked Dec 26, 2016
500 views
Arrange the following synchronization constructs in increasing order of cost:A. SemaphoreB. MutexC. Monitor
1 votes
1 votes
2 answers
4
sh!va asked Dec 26, 2016
1,251 views
Interview question:Which of the following can be used inside Interrupt Service routine?1. Semaphore2. mutex3. Both 1 and 24. neither 1 nor 2