I understood that when the function changes the value of pointer (and not the value witch the pointer points..), we should be use a double pointer. This because the function works on a "copy" of arguments passed, so, at the end, the function doesn't will change the original pointer's value..right?
I'm always working on my Doubly Linked List, that until this moment I wrote using only single pointers, and all works!
This is my structs (In italian lista = list):
For example, I have this function Add() that insert a node at the end of list:Code:typedef struct Node { void *data; struct Node *next; struct Node *prev; }Node; typedef Node* iterator; typedef struct Lista { Node *head; Node *tail; int length; }Lista;
I have seen more times this code written using double pointers..but why? In my code, lista->tail pointer remains changed..then, when I should use double pointers?!Code:void Add(Lista *lista, void *data) { Node *n = New_Node(data); if (!lista->tail) lista->head = n; else { lista->tail->next = n; n->prev = lista->tail; } lista->tail = n; lista->length++; }