*talloc 照书中定义,编译出错
#include <stdio.h>
struct node {
int element;
struct node *next;
}
struct node *talloc()
{
return (struct node *) malloc(sizeof(struct node));
}
为何DEV CPP 编译时提示:
two or more data types declaration of 'talloc '
后面的程序如下
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;
}
[解决办法]
struct node {
int element;
struct node *next;
};/*要加分号*/
malloc的内存空间,最后用完要free释放