edited by
1,672 views
10 votes
10 votes

In programming languages like C, C++, Python $\dots$ the memory used by a program is typically separated into two parts, the stack and the heap. Consider the following statements:

  1. A stack is efficient for managing nested function calls.
  2. Stack space is limited while heap space is not.
  3. The stack cannot be used for persistent data structures.

Then:

  1. $1$ and $2$ are true but $3$ is false.
  2. $1$ and $3$ are true but $2$ is false.
  3. $2$ and $3$ are true but $1$ is false.
  4. All three statements are true.
edited by

3 Answers

Best answer
13 votes
13 votes

Option (B) 1 and 3 are true but 2 is false. 

2 is FALSE because Size of heap and stack both are limited by the available main memory. Usually the OS also restricts the maximum memory a process can use. 

1. is TRUE because stack facilitates creation of memory for function calls and free them on function return - just a change of stack pointer is needed. 

3. is TRUE because the stack variables are cleared on function return. Usually persistent data structures refer to those which survive program exits but even for static variables which should live until program finishes, stack cannot be used. 

selected by
1 votes
1 votes
In the case of recursion stack is the best storage allocation technique also in nested fuction sometimes it is also called as the recursion.

When we see activatio records of any process inside the memory we found there are severalparts

In activation records::

.exe file (machine code)

Static and global variable storage allocation spaces.

Heap (Increase upwards and inversely propotional to stack size and opposite to stack)

Stack(For recursion and bound to fresh allocation)

So statement two will be wrong.

Third statement is that Stack is not primitive data structure.
0 votes
0 votes

Ans = (B). Statement 2 is false. As both the stack and heap are finite. One can move the 'Program Break' (brk) to increase or decrease the heap memory (malloc shifts the brk)

Related questions

1 votes
1 votes
1 answer
3