Code:
#include<stdio.h> #include<malloc.h> struct node {int a; struct node *next; }; int main() { int i=0; struct node *p,*head; for( i=0;i<5;i++) { p=(struct node*)malloc(sizeof(struct node)); if(head==NULL) { head=p; head->next=NULL; } else { p->next=head; head=p; } } for(i=0;i<2;i++) { printf("%d ",head->a); head=head->next; } return 0; }
Comment