46.9k views
4 votes
Given the following code, assume the myStack object is a stack that can hold integers and that value is an int variable. Assume that the pop function, called on lines 4 and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?

User Publicus
by
4.7k points

1 Answer

4 votes

Answer:

The statement in line 7 is 0 .

Step-by-step explanation:

Let suppose the function is where myStack object is a stack and value is in integer.

As line 4 and 6 store the pop number from stack then we have the following number line with stack variable value.

Let us consider the following line of code. where we have some line such as

1.myStack.push(0);

2.myStack.push(1);

3.myStack.push(2);

4.myStack.pop(value);

5.myStack.push(3);

6.myStack.pop(value);

7.cout << value << endl;

Line 4 and 6 called on the value as shown.

Asusume the pop function the line 5 store the number that is 3.As the pop function in line 4 , 5 and 6 store the number popped from the stack value then the statement in line 7 is 0 .

User Stanimir Dimitrov
by
4.9k points