c - 2 ways of initializing a linked list, do they equal? -
typedef struct node{ int data; struct node* next; }listnode; void init(listnode **head){ (*head) = (listnode *)malloc(sizeof(listnode)); (*head)->next = 0; } listnode* another_init(){ listnode *head = (listnode *)malloc(sizeof(listnode)); return head; }
i have problems:
1.in function init,why should put second rank pointer ?
2.is function init same another_init ?
another_init not "the same as" init. doesn't set next-pointer 0. malloc(3): malloc() allocates size bytes , returns pointer allocated memory. memory not cleared.
Comments
Post a Comment