| |

VerySource

 Forgot password?
 Register
Search
View: 720|Reply: 3

* talloc as defined in the book, compilation error

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 11:00:02
| Show all posts |Read mode
#include <stdio.h>
struct node {
       int element;
       struct node * next;
       }

struct node * talloc ()
{
       return (struct node *) malloc (sizeof (struct node));
}

Why does DEV CPP prompt when compiling:
two or more data types declaration of 'talloc'

The following procedure is as follows

main ()
{
      struct node * head;
      struct node * rear;
      struct node * p;
      head = talloc ();
      (* head) .element = 1;
      head-> next = NULL;
      
      rear = talloc ();
      (* rear) .element = 2;
      rear-> next = NULL;
      
      head-> next = rear;
      p = head;
      while (p-> next! = NULL) {
            printf ("% d\n", (* p) .element);
            p = p-> next;
            }
            
      return 0;
}
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-1-3 15:30:01
| Show all posts
struct node {
       int element;
       struct node * next;
       }; / * Semi-colon * /

malloc memory space, finally free up to use up
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-3 15:54:02
| Show all posts
struct node {
       int element;
       struct node * next;
       }
Add a semicolon!
Classes and structures are defined with a semicolon at the end.
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-5 15:36:01
| Show all posts
It is estimated that a struct is removed after return
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list