ITPEC FE Subject B October 2025 Question 8

Source exam: ITPEC FE Subject B October 2025Topic: Stack

ITPEC FE Subject B October 2025 — Question 8 of 20

Stack uses array stck[1..10] with tos as top-of-stack pointer, initially 0 (empty).

Push logic:
- Check overflow: tos = 10 → full

- A: tos ← tos + 1 (move pointer up first)

- Then stck[tos] ← item (store at new top)

Pop logic:
- Check underflow: tos < 1 → empty

- B: item ← stck[tos] (read current top), then tos ← tos - 1 (move pointer down)

- Return item

Why not others:
- a) — Pop increments tos (tos + 1) instead of decrementing — wrong direction

- c), d) — Pop section has wrong order or direction for tos

- e)h) — Push decrements tos, but since tos starts at 0 and array starts at 1, push must increment

Key rule: When tos points to the current top element (not the next free slot), push increments before writing, pop reads before decrementing.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.