edited by
2,374 views
10 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.

3 Answers

Best answer
12 12 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 1 vote
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 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)

Position:
Show:

Related questions

7 7 votes
1 answers 1 answer
2.1k
2.1k views
go_editor asked May 19, 2016
2,119 views
In programming language terminology, $\text{ call by value }$ refers to the fact that:A function call can return a value.When a function is called, arguments are copied i...
5 5 votes
1 1 answer
839
839 views
go_editor asked May 19, 2016
839 views
Consider the following functions $f$ and $g$:f(){ x = x+1; x = y*y; x = x-y; }g(){ y = y+1; y = x*x; y = y-x; }Suppose we start with initial values of $1$ for $x$ and $2$...
1 1 vote
1 1 answer
1.7k
1.7k views
go_editor asked May 19, 2016
1,715 views
You have a laptop with a fixed amount of memory and hard disk space and no external storage devices connected (CD, USB drives, . . . ). Which of the following is the most...
25 25 votes
4 answers 4 answers
3.4k
3.4k views
go_editor asked May 19, 2016
3,433 views
Let $G=(V, E)$ be a graph. Define $\overline{G}$ to be $(V, \overline{E})$, where for all $u, \: v \: \in V \: , (u, v) \in \overline{E}$ if and only if $(u, v) \notin E$...