| 为什么free 后的结果与free前相同 #include
#include
typedef struct linklist* slink;
struct linklist
{
int data;
slink next;
};
slink head; /* head */
slink create_list();
void main()
{
slink top;
int icount;
printf(" create linklist \n");
printf("head address %x\n",head);
/* printf("head data =[%d]\n",head->data); */
create_list( );
head->data = 999;
printf("head address %x\n",head);
printf("head data =[%d]\n",head->data);
printf("head next = %x\n",head->next);
free( head );
/* head = NULL; */
printf("free \n");
printf("head address %x\n",head);
printf("head data =[%d]\n",head->data);
printf("head next = %x\n",head->next);
}
slink create_list( )
{
head = (slink*)malloc( sizeof(slink) );
head->next = NULL;
return head;
} |