Linked Lists
Learn how linked lists work and how to implement operations like insertion and deletion.
Linked Lists is a free C Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Linked Lists in C
A linked list is a dynamic data structure where elements (nodes) are connected using pointers.
In this lesson, you will learn:
- How linked lists work.
- How to insert and delete nodes in a linked list.
- The advantages of linked lists over arrays.

3
Example: Defining a Linked List Node
In C, a linked list node is defined using a struct with a data field and a pointer to the next node.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
int main() {
struct Node *head = NULL;
return 0;
}4
Inserting a Node at the Beginning
To insert a new node at the beginning of a linked list:
- Create a new node.
- Set its
nextpointer to the current head. - Update the head pointer.
5
Example: Inserting a Node at the Beginning
This program inserts a new node at the beginning of a linked list.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
void insertAtBeginning(struct Node **head, int newData) {
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = newData;
newNode->next = *head;
*head = newNode;
}
int main() {
struct Node *head = NULL;
insertAtBeginning(&head, 10);
printf("Inserted: %d\n", head->data);
return 0;
}6
Deleting a Node
To delete a node from a linked list:
- Find the node to be deleted.
- Update the previous node’s
nextpointer. - Free the memory of the deleted node.
7
Example: Deleting a Node
This program deletes a node from a linked list.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *next;
};
void deleteNode(struct Node **head, int key) {
struct Node *temp = *head, *prev;
if (temp != NULL && temp->data == key) {
*head = temp->next;
free(temp);
return;
}
while (temp != NULL && temp->data != key) {
prev = temp;
temp = temp->next;
}
if (temp == NULL) return;
prev->next = temp->next;
free(temp);
}
int main() {
struct Node *head = (struct Node*)malloc(sizeof(struct Node));
head->data = 10;
head->next = NULL;
deleteNode(&head, 10);
return 0;
}8
9
Advantages of Linked Lists
Linked lists have several advantages over arrays:
- Dynamic size (no need to specify size beforehand).
- Efficient insertions and deletions.
- No memory wastage due to fixed sizes.
10
Summary
In this lesson, you learned:
- What linked lists are and how they work.
- How to insert and delete nodes.
- The advantages of linked lists over arrays.
Next, we will explore stacks and queues in C!

Frequently asked questions
Is the “Linked Lists” lesson free?
Yes — the full text of “Linked Lists” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.
What will I learn in “Linked Lists”?
Learn how linked lists work and how to implement operations like insertion and deletion. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Linked Lists” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Linked Lists
- Stacks and Queues
- Trees and Graphs