[求助]关于free()函数的用法!
题目:链表的插入(某些函函数程序没写)#include<stdio.h>
#include<stdlib.h>
struct NUM
{
int num;
struct NUM *next;
};
#define LEN sizeof(struct NUM)
struct NUM *insert(struct NUM *head,struct NUM *p0);
void print(struct NUM *head);
struct NUM *release(struct NUM *head);
int main()
{
struct NUM *newnode;
struct NUM *headpoint;
int number;
headpoint=NULL;
printf("输入一个数,输入0结束:");
scanf("%d",&number);
while(number!=0)
{
newnode=(struct NUM *)malloc(LEN);
if(!newnode)
{
printf("内存不足!!\n");
return 0;
}
newnode->num=number;
headpoint=insert(headpoint,newnode);
printf("输入一个数,输入0结束:");
scanf("%d",&number);
}
printf("插入结束!\n");
print(headpoint);
headpoint=release(headpoint);
return 0;
}
...............
..............
struct NUM *release(struct NUM *head)
{
struct NUM *p=head;
while(head)
{
head=p->next;
free(head);
p=head;
}
return head;
}
问题:为什么调用时要headpoint=free(headpoint),能不能把它改成free(headpoint)?
还有,为什么要返回值?不要返回值行不?