To delete a node, unlink it by making its predecessor point to its successor, then free it. Deleting the head must update the head pointer. A neat technique is a pointer to a pointer (struct Node **pp), which treats the head and interior links the same way.
pp points at the link that points to the current node.
Rewriting *pp unlinks the node, even when it is the head.
The function returns 0 when the value is absent.
Edge Cases & Pitfalls
Check these before relying on Deletion in a Linked List in C in real programs.
uaf
Using a node after free
Do not read t->next after free(t).
leak
Unlinking without freeing
Forgetting free leaks the node.
Remember
Key Takeaways
Unlink, then free.
Pointer-to-pointer unifies head and middle.
Return a status.
One line: To delete a node, unlink it by making its predecessor point to its successor, then free it.
Frequently Asked Questions
Find its predecessor, set predecessor->next to node->next, then free the node. For the head, update the head pointer instead.
It lets one loop handle both the head and interior nodes without a special case.
Continue with "Searching a Linked List in C" next. Find a value in a linked list with a linear scan. The C Linked Lists hub lists every topic in order.