#include <stdio.h>
#include <stdlib.h>

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

void headpt(struct Node *head) {
    struct Node *tmp = head;
    while (tmp != NULL) {
        printf("%d ", tmp->data);
        tmp = tmp->next;
    }
    printf("\n");
}

int main() {
    struct Node *head = malloc(sizeof(struct Node));
    head->data = 1;
    head->next = NULL;

    struct Node *newNode = malloc(sizeof(struct Node));
    newNode->data = 2;
    newNode->next = NULL;
    head->next = newNode;//this one points the above data to next node

    newNode = malloc(sizeof(struct Node));
    newNode->data = 3;
    newNode->next = NULL;
    head->next->next = newNode;
    
    newNode = malloc(sizeof(struct Node));
    newNode->data = 4;
    newNode->next = NULL;
    head->next->next->next = newNode;

    headpt(head);

    // Free allocated memory
    struct Node *current = head;
    while (current != NULL) {
        struct Node *frt = current->next;
        free(current);
        current = frt;
    }

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: