The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
107 views

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);
}
}

asked in Programming by (231 points) | 107 views
0

You are declaring a function which would be taking a pointer to structure even before declaring the structure. In the function declaration. This is the modified program https://ideone.com/KPQgV4 @Ahsanul, regarding the node * part you can ignore that as most compilers are not throwing any error.

0

I did't understand the difference between func(struct node *); and func(struct node*).

Can you please explain it to me?

+1

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

0

@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? 

+1
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

Please log in or register to answer this question.

Related questions

0 votes
0 answers
2
asked Nov 4 in DS by srestha Veteran (103k points) | 164 views


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,240 questions
49,722 answers
163,928 comments
65,837 users