Why do we need a temp variable?
Without temp, you can lose access to the current node or the remainder of the list while rewiring pointers.
LazyCoder
Practice reversing a singly linked list and see how head, temp, and prev change at every step.
Written by Vignesh Reddy Julakanti.
Founder of Engineering Animuthyam.
Published: 2026-03-22. Updated: 2026-04-02.
This page is written for learners who need visual, interview-oriented linked list explanations rather than a short definition.
Reversal is not about memorizing a pattern. It is about preserving access to the remaining nodes while you redirect the current next pointer. This page keeps the visual state and code trace in sync so the sequence is explicit.
This is one of the most common linked list interview exercises because it tests pointer discipline. If you can explain the order of assignments clearly, you usually understand the structure well enough to handle harder variants.
Learners usually know the three variables by name but still lose the chain during the second or third iteration. The failure is almost always about sequence, not syntax. This page is built to make that sequence obvious.
Without temp, you can lose access to the current node or the remainder of the list while rewiring pointers.
The original head becomes the last node, so its next pointer must end at null.