typedef struct n{
        int num;
        struct n *next;
}node;

node is the structure to create the linked list.

node *list1;

I have created a linked list ( list1 )like this 1 -> 2 -> 3 -> 4

so i free it like this ----

free(list1 -> next -> next ->next);
free(list1 -> next -> next);
free(list1 -> next);
free(list1);

when i am printing the list after each free, it is always printing a
list of length 4, isn't the values free'd when we do free() ?

actual printing gives
1 2 3 0
1 2 garbage 0
1 garbage garbage 0
garbage garbage garbage 0

why is the linked list still connected ?


actual print function -----
void print(node *l)
{
     while(l != NULL)
    {
        printf("%d\t",l->num);
        l = l->next;
    }
    printf("\n");
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to