Freeing the memory of structure in C -
i have following sturcture creating linked list, how can free allocated memeory?
typedef struct linked_list { struct linkedl_ist *number; pointer house; } list; typedef list *list; typedef void pointer
i have following list
list l1; l1 = some_function(pointer);
these l1
constructed using variables. linked list data structure mentioned. how can free memory allocated l1
?
[edit]
l1
holds memory of 8 byte.
l1
doesn't need freed. it's on stack. return function you're in , automatically go away. way free l1
points same way free rest of elements of list: walk list (using ->number
) , free each element go.
list node = l1; list next; while (node != null) { next = node->number; free(node); node = next; }
Comments
Post a Comment