C language: Releasing memory of pointers to struct

后端 未结 4 1628
一整个雨季
一整个雨季 2021-01-20 06:28

Say I have declared a pointer to a struct and assign it with malloc() using this definition

typedef struct node {
    int info;
    struct node *next;
} NODE         


        
4条回答
  •  余生分开走
    2021-01-20 06:50

    node1 is a pointer, meaning the value of it is the virtual memory address of the allocated struct.

    Assigning node2 = node1 just copies that address.

    As a result free(node1) and free(node2) are equivalent.

提交回复
热议问题