in Programming in C retagged by
575 views
0 votes
0 votes

Can anyone  check this program?

I got some warning.

#include<stdio.h>
#include<stdlib.h>
void func(struct node *);
    struct node
{
     int data;
   struct node *next;
};
   int main()
{
    struct node *head=(struct node *)malloc(sizeof(struct node));
 struct node *temp=(struct node *)malloc(sizeof(struct node));
  struct node *first=(struct node *)malloc(sizeof(struct node));
   head->data=10;
   head->next=temp;
   temp->data=20;
   temp->next=first;
   first->data=30;
   first->next=NULL;
       func(head);
return 0;
}

void func(struct node *p)
{
   if(p)
{   
    printf("\n%d",p->data);
  func(p->next);
}
}

in Programming in C retagged by
575 views

4 Comments

You did one mistake which is 

void func(struct node *); 

You must first declare the structure first and then any function related to the structure, just declare void func after structure declaration and code will run

1
1

@Tesla! in some compilers for void func(struct node<space> *) there is an error saying that func argument taken as struct node but should be pointer but in some there are no errors, why is it so? 

0
0
don't know that but gcc is not throwing any error, must try on few another compiler to see if it is a syntax issue or compiler
1
1

1 Answer

0 votes
0 votes
do the global function prototyping  after the structure definition

Related questions