1,559 views
2 votes
2 votes
Runtime stack doesnot contain

(A) Local variables

(B) Static Variables

(C) Parameter Passed

(D) Return Address

3 Answers

Best answer
3 votes
3 votes
Answer is (b) static variables.

(a) Local variables have lifetime only till function call completes execution and are popped off the stack once execution is completed.

(b) Since static variables preserve their value even after the function execution is done, they must not be present on execution stack. Contents of stack are emptied once the function returns and if static variables would be present in stack, then we would loose their value.

(c) In order to understand this, we can consider the following simple example:

factorial(n)

{    

       if(n==1)    return 1;

       else          return n*factorial(n-1);

}

For each function call, the new value of parameter is pushed onto the stack and the return values are computed accordingly.

(d) We need return addresses to return the control so that execution can be resumed after the function call.
selected by
2 votes
2 votes

Local variables are definitely in the Stack.

Parameters passed are also Variables which are passed from the calling function so they are also the part of stack.

Return address is there in the function call stack so it is also the part of Stack...

Only the static variables are not the part of the stack.

They are created onces and available in shared mode....present in Global/static region...

0 votes
0 votes
static variables should be present in heap.hence static variables doesn’t present in stack

Related questions

2 votes
2 votes
0 answers
1
1 votes
1 votes
1 answer
2
shivangi5 asked Dec 12, 2017
636 views
Options areTI==(P/Q*i-1)Ti==(P/Q*i+1)Ti==(P/Q*(i-1)-1)Ti==(P/Q*(i+1)-1)
0 votes
0 votes
1 answer
3
2 votes
2 votes
1 answer
4
Rahul Jain25 asked Oct 7, 2016
634 views