C PROGRAM TO CREATE A LINKED LIST
Sunny Bhaskar
11/9/20241 min read
#include <stdio.h>
#include <stdlib.h>
// Define the structure for a node
struct Node {
int data; // To store the data
struct Node* next; // Pointer to the next node
};
int main() {
// Creating nodes
struct Node* head = (struct Node*)malloc(sizeof(struct Node));
struct Node* second = (struct Node*)malloc(sizeof(struct Node));
struct Node* third = (struct Node*)malloc(sizeof(struct Node));
// Assigning data and linking nodes
head->data = 10; // Assign data to the first node
head->next = second; // Link first node with the second node
second->data = 20; // Assign data to the second node
second->next = third; // Link second node with the third node
third->data = 30; // Assign data to the third node
third->next = NULL; // End of the list
// The linked list is now: 10 -> 20 -> 30 -> NULL
return 0;
}