Multiple choiceThe statements stackPushitem11 stackPopitem1

(Multiple choice)The statements

stack.Push(item1+1) ;

stack.Pop(item1+1];

in the client program

a)Would cause a syntax error at compile time.

b)Would cause a run-time error.

c)Would be legal,but would violate the encapsulation of the stack.

d)Would be a perfectly legal and appropriate.

Give the answer and explain why in detail.

Solution

a)Would cause a syntax error at compile time.

stack.Push(item1+1) ;-->Its valid because we are pushing item1+1 into stack.
stack.Pop(item1+1]);--> Its Invalid

But While popping something out of stack we dont specify elemenet. Stack will pop the topmost element, You dont need to give any argument. So it will result in Compile time error.

(Multiple choice)The statements stack.Push(item1+1) ; stack.Pop(item1+1]; in the client program a)Would cause a syntax error at compile time. b)Would cause a ru

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site