pointers - Manipulating linkedlists in C -
why have pass pointer pointer manipulate linked list? why can't pass pointer? dont understand internals of happening logically.
i see passing in pointer list suffice, apparently not.
it depends on linked list implementation, sake of argument, if have implemented, say, push function, this:
typedef struct linked_list linked_list; struct linked_list { int value; linked_list *next; }; void push(linked_list **head, int value) { linked_list *temp = *head; *head = malloc(sizeof(linked_list)); (*head)->value = value; (*head)->next = temp; } then pointer pointer necessary because, otherwise, modifying push's local head variable, , not caller's.
Comments
Post a Comment