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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -