# Thread: Why I should be use double pointers?

1. ## Why I should be use double pointers?

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):
Code:
```typedef struct Node {
void *data;
struct Node *next;
struct Node *prev;
}Node;

typedef Node* iterator;

typedef struct Lista {
Node *tail;
int length;
}Lista;```
For example, I have this function Add() that insert a node at the end of list:
Code:
```void Add(Lista *lista, void *data) {
Node *n = New_Node(data);
if (!lista->tail)
else {
lista->tail->next = n;
n->prev = lista->tail;
}
lista->tail = n;
lista->length++;
}```
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?!  2. You encapsulated the node into a list, so you already have an indirect "double pointer", i.e., the pointer to the list, with the list's member pointer pointing to the node.

Try writing the function without the list struct:
Code:
```void Add(Node *head, Node *tail, int length, void *data) {
Node *n = New_Node(data);
/* ... */
}```
You will soon see that it has to be:
Code:
```void Add(Node **head, Node **tail, int *length, void *data) {
Node *n = New_Node(data);
/* ... */
}```
hence the advantage of having the list struct. 3. ##  Originally Posted by laserlight You encapsulated the node into a list, so you already have an indirect "double pointer", i.e., the pointer to the list, with the list's member pointer pointing to the node.
Ohhh I get it!  Thank you!

At this point, I would like to know for what purposes (or into what Abstract Data Type) double pointers are most used.  Linus on understanding pointers - Gregory Trubetskoy

Especially the part where it says

What Linus was saying is that the above code could be simplified by making the previous element a pointer to a pointer rather than just a pointer.
and the code example given in that context 5. Originally Posted by Hodor Linus on understanding pointers - Gregory Trubetskoy

Especially the part where it says

and the code example given in that context

Did it! I will needed a lot of practice to understand completely this argument.. 6. Using a double pointer also simplifies the code for scanning a list where the initial pointer is the head pointer, and later pointers are node's next pointers, eliminating the need for a conditional to check if working with the head or a node:

Code:
```/* initialize ptr to ptr to node */ Popular pages Recent additions double, node;, pointer, pointers, struct 