Deleting linked lists.

Byron Warner warner at weiss.cs.unc.edu
Wed Mar 27 10:43:26 AEST 1991


I was wondering, is it safe to unallocate a singly linked list like this:

struct list *head; /* top of list */
struct list *ptr = head;
while (ptr){
	free(ptr);
	ptr = ptr->next;
}

I am not sure if I can assume that
the value of ptr will not be corrupted
after it is freed.

-- 
----
Byron F. Warner					warner at cs.unc.edu
University of North Carolina - Chapel Hill	Computer Sci Department
"The opinions expressed here should be yours."



More information about the Comp.lang.c mailing list