nopes , they are not connected, it is just a chance you are getting
the same values and nothing is overwritten there: basically these are
DANGLING POINTERS . Now you should keep practising something like this

#define FREE(N) { free(N); N=NULL;}

to avoid such mistakes

On Nov 11, 3:41 pm, shady <sinv...@gmail.com> wrote:
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to