# Thread: double astrix pointer question..

1. ## double astrix pointer question..

what this function does?

Double astrix says that the parameter is the pointer which P points at
so the parameters is p->next and num.
They create a node called elt ,they assign it a memory space in a size node
and make it a node pointer.
next they say that elt->next=p->next
elt->value is num
and p->next=elt

I cant imagine what is the structure of the combination of those to marked red lines.
??
Code:
```typedef struct node {
int value;
struct node *next;
}Node;

void what1(Node ** p,int num){
Node *elt;
elt=(Node*)malloc(sizeof(Node));
elt->next=*p;
elt->value=num;
*p=elt;
}```

2. pass by reference anyone?

3. Originally Posted by transgalactic2
what this function does?

Double astrix says that the parameter is the pointer which P points at
so the parameters is p->next and num.
The parameter is a pointer that points to the pointer which points to a Node. The ** means a pointer to a pointer.
So the parameter is p and num.
There is also a pointer which p points at. Lets call it nodePtr. There is also a node in which nodePtr points to. Lets call it node.

You have this:
p -> nodePtr -> node

So:
elt-> next = *p means: elt->next = nodePtr
*p = elt means: nodePtr = elt

4. Originally Posted by audinue
pass by reference anyone?
In C?

What I think you want is
Code:
`(*p)->next`
If I understand you correctly.

5. It basically takes the address of a pointer to which it assign malloced memory. Only a pointer can store an address, so there you go.

6. I think EVOEx is on the mark if I understand your question. p is a pointer to pointer to a Node while *p is a pointer to a Node object as in
Code:
```elt->next=(*p)->next
(*p)->next=elt```

7. what means Node **p in the signature??

p->next ?(a pointer which points to a pointer)

am i correct?

8. p isn't the same as p->next if that is what you mean. I answered what p means in post #3.

It is indeed a pointer that point to a pointer. So its value (*p) is a pointer that points to a node. So p points to a pointer which pointer points to a node.

9. Originally Posted by transgalactic2
what means Node **p in the signature??

p->next ?(a pointer which points to a pointer)

am i correct?
Node** means it is a pointer to a variable of type Node*. It can be no more simple than that.
And the "p->next" syntax just means "(*p).next", and since *p is a Node*, it is illegal.

10. so **p point to a Node * type variable

what point to what during this function (in every step)

??

11. Originally Posted by transgalactic2
so **p point to a Node * type variable
No, if p is a Node**, then **p is a Node.

12. but what is the stucture of **p regarding a linked list system.

I cant imagine what points to what in every step during the running of this function.
Code:
```typedef struct node {
int value;
struct node *next;
}Node;

void what1(Node ** p,int num){
Node *elt;
elt=(Node*)malloc(sizeof(Node));
elt->next=*p;
elt->value=num;
*p=elt;
}```

13. Originally Posted by transgalactic2
I cant imagine what points to what in every step during the running of this function.
What exactly is the part that you cannot understand?

Look, you have to try and explain what the function does. If you cannot fully explain it, at least show some effort by explaining these two lines:
Code:
```Node *elt;
elt=(Node*)malloc(sizeof(Node));```
Then try to explain what this line does:
Code:
`elt->next=*p;`

14. I dont know what it does.
I was asked to explain what it does.
i can guess but this doble astrix thing and linked list
i dont know whats happening in the linked list when the double astrix involved.

Code:
```typedef struct node {
int value;
struct node *next;
}Node;

void what1(Node ** p,int num){
Node *elt;
elt=(Node*)malloc(sizeof(Node));  //create a node called elt ,assign it some memory
elt->next=*p;     //from this point i dont know what the effect of the double astrix
elt->value=num;
*p=elt;
}```

15. Okay, at least you got the first part. Now, what is the type of elt->next? What is the type of *p?