C Linked Lists

Intermediate
16 min read
Updated: Nov 2026
1 example
10 guides

Definition and Usage

A linked list is a chain of nodes. Each node stores a value and a pointer to the next node, so the list grows and shrinks one node at a time without moving other elements. Unlike an array it has no random access, but inserting or deleting at a known position needs no shifting. This section covers nodes and links, creating and traversing lists, insertion, deletion, searching, reversing, doubly linked lists, and circular lists.

Draw the pointers.

Most linked-list bugs are pointer-order mistakes. Sketch boxes and arrows, and update new links before breaking old ones.

Learning Path

Work through the stages in order, or jump to a topic from the index below (10 tutorials).

C Examples

A quick taste of linked lists. Compile with gcc file.c -std=c11 -Wall -o out.

Example 1 — A three-node list

Link nodes by hand and walk the chain until NULL.

C
#include <stdio.h>

struct Node {
    int data;
    struct Node *next;
};

int main(void) {
    struct Node c = {30, NULL};
    struct Node b = {20, &c};
    struct Node a = {10, &b};

    for (struct Node *p = &a; p != NULL; p = p->next) {
        printf("%d -> ", p->data);
    }
    printf("NULL\n");
    return 0;
}

How It Works

  1. Each node holds a value and the address of the next node.
  2. The last node's next is NULL, which ends the loop.
  3. Real lists allocate nodes with malloc instead of declaring them by name.

C Linked Lists Topics

Every guide in this section with a one-line summary (10 tutorials).

Build a list

4 tutorials

Nodes, links, creation, and traversal.

TopicDescriptionTutorial
Linked list basicsWhat a linked list is and how it compares to an array.Try it
Nodes and linksDesign the node struct, allocate nodes, and connect them.Try it
Creating a linked listBuild a list from data by appending nodes to the tail.Try it
Traversing a linked listVisit every node to print, count, sum, or process the list.Try it

Operations

4 tutorials

Insert, delete, search, and reverse.

TopicDescriptionTutorial
InsertionInsert at the head, tail, or a given position.Try it
DeletionRemove nodes safely by head, value, or position and free them.Try it
SearchingFind a value in a linked list with a linear scan.Try it
Reversing a linked listReverse the list in place with three pointers.Try it

Variants

2 tutorials

Doubly linked and circular lists.

TopicDescriptionTutorial
Doubly linked listsNodes with prev and next pointers allow walking both ways.Try it
Circular linked listsThe last node links back to the first for endless looping.Try it

Edge Cases & Pitfalls

Common mistakes when learning linked lists in C.

leak

Losing the head

Overwriting the only pointer to the first node leaks the whole list.

null

Dereferencing NULL

p->next->data crashes at the end of the list. Test p->next first.

free

Freeing then reading

Save p->next before calling free(p).

Key Takeaways

  • Node: value plus next pointer.
  • End: NULL.
  • Ownership: free every node.

One line: A linked list is a chain of nodes.

Frequently Asked Questions

A linked list is a sequence of dynamically allocated nodes, each containing data and a pointer to the next node.
Use a linked list when you insert or delete often in the middle and do not need random access by index. Arrays are faster for indexed access and iteration.
O(n), because you may need to visit every node.

Next: Linked List Basics

What a linked list is and how it compares to an array.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful