In the below stack operation, what will be the output value for the variable 'result'?
result = 0
stack = [10,20,30]
stack.append(40)
result +=stack.pop()
result +=stack.pop()
In the below stack operation, what will be the output value for the variable 'result'?
result = 0
stack = [10,20,30]
stack.append(40)
result +=stack.pop()
result +=stack.pop()
Solution
✅ Correct Option: 1
append(40) puts 40 on top, so the stack is . pop() removes and returns the top element (last in, first out).
The first pop returns 40, leaving . The second pop returns 30, leaving .
Related questions:
2026: 31 May Shift 1
2026: 26 May Shift 1
2025: 27 May Shift 2
2025: 15 May Shift 2
2026: 20 May Shift 1
2026: 23 May Shift 1