+ 3
What's the error in this C Program of Linked List?
#include<stdio.h> #include<conio.h> struct node { int info; struct node *next; }; int main() { struct node *head,*p,*q,*r; p->info=5; p->next=NULL; q->info=9; q->next=NULL; r->info=7; r->next=NULL; p->next=q; q->next=r; head=p; while(head!='\0') { printf("%d",head->info); head = head->next;} return 0; }
2 Respuestas
+ 1
/* @vukan,kurwius the above soln is given by my college professor but what was the logic behind this ...can anyone explain this ??? */
/* 😢 */
#include<stdio.h>
#include<conio.h>
struct node
{
int info;
struct node *next;
};
int main()
{
struct node *head,a,b,c,*p,*q,*r;
p=&a;
q=&b;
r=&c;
p->info=5;
p->next=NULL;
q->info=9;
q->next=NULL;
r->info=7;
r->next=NULL;
p->next=q;
q->next=r;
head=p;
while(head!='\0')
{
printf("%d",head->info);
head = head->next;}
return 0;
}
+ 3
i think that you must initizale head to something before give it value of p