LinkedList - How to free the memory allocated using malloc

后端 未结 5 623
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 20:53

I have a very simple C code for constructing a Singly Linked list as below, in which I allocate memory for each node dynamically using malloc. At the end of code, I want to

5条回答
  •  忘掉有多难
    2020-12-23 21:22

    I use something like this:

    for (p = curr; NULL != p; p = next) {
        next = p->next;
        free(p);
    }
    

提交回复
热议问题