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

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

void print_linked_list(struct node *n)
{
  while(n!=NULL)
    {
       printf("%d ",n -> data);
    n = n -> next;
    }
}

int main()
{
  struct node *first = NULL;
  struct node *second = NULL;
  struct node *third = NULL;

  first = (struct node*)malloc(sizeof(struct node));
  second = (struct node*)malloc(sizeof(struct node));
  third = (struct node*)malloc(sizeof(struct node));

  first->data=1;
  first->next=second;
  second->data=2;
  second->next=third;
  third->data=3;
  third->next=NULL;

print_linked_list(first);
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter