Course contentsShow
← Computer Science
Lesson 326 of 2,8728. Linked Data StructuresFree lesson

Head Pointer and Empty Lists

Using a head pointer to track the first node; representing an empty list with null/None.

Head Pointer and Empty Lists

What you'll learn: How to keep track of where your linked list starts and what an empty list looks like in memory.


The Head Pointer

In a linked list, you need a way to access the entire chain of nodes. The head pointer is a special pointer variable that always points to the very first node in your list. Think of it like a bookmark that marks the beginning of a chapter—without it, you'd have no way to find where the list starts.

head → [data|next] → [data|next] → [data|NULL]

The head pointer itself is not a node—it's just a pointer variable that stores the memory address of the first node. If you lose the head pointer, you lose access to the entire list (this would create a memory leak).


Representing an Empty List

What happens when your linked list has no nodes at all? An empty list is represented by setting the head pointer to NULL (or None in some languages). This signals "there is no first node."

head → NULL

This is a critical concept: an empty list isn't the absence of a head pointer—it's a head pointer that points to nothing. You still have the variable head, but its value is NULL.

Before accessing any node, you should always check if the head is NULL to avoid dereferencing a null pointer, which would crash your program.


Key Takeaway: The head pointer tracks the first node in a linked list; when the head pointer is NULL, the list is empty.