Skip to content

Stack: Peek

Task: Read the top value without removing it

ABCtopAFTER THE PEEKABC

What you are watching

Peek returns the value on top and leaves the stack exactly as it was. It is the operation that separates looking from taking: after a peek the stack still holds three values and the top pointer has not moved. Only the top value can be read this way - there is no operation that reaches past it to B or A.