i cant see how it puts a new head
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;
}```
if p is our head of the list
then we can just do this
Code:
```void what1(Node ** p,int num){
Node *elt;
elt=(Node*)malloc(sizeof(Node));
elt->next=p;
elt->value=num;

}```
i cant understand the first code

2. p is pointer to the head pointer, which gives the possibility to update the head pointer value (in the line you have removed)

3. p is the head of the list
so if we want to put one node before it
what is the meaning of *p
if our p is defined as node **p
??

4. Originally Posted by transgalactic2
p is the head of the list
so if we want to put one node before it
what is the meaning of *p
if our p is defined as node **p
??
you sure know better what this code means even when you do not understand what it does...

I do not see a way to explain you something

5. Originally Posted by transgalactic2
p is the head of the list
so if we want to put one node before it
what is the meaning of *p
if our p is defined as node **p
??
I believe what Vart is trying to say is that the head of the list, has to be updated, so it can stay as the head of the list.

You can't / shouldn't, put a node in front of the head of the list, unless you make that node, the new head of the list.

Otherwise, the head of the list, will not stay the head of the list.

6. is this code doing the same job as the first one

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

}```

7. Originally Posted by transgalactic2
is this code doing the same job as the first one
it does not

You have not believe the first time. I hardly think you will believe it from the second. I do not understand, why you continue to ask questions if you ignore the answers ...

8. because its a very simple logic where i say that then next of some node will be the head of the list

why its wrong??

9. you said
"p is pointer to the head pointer, which gives the possibility to update the head pointer value "

but you didnt say why my method is wrong

10. Originally Posted by transgalactic2
you said
"p is pointer to the head pointer, which gives the possibility to update the head pointer value "

but you didnt say why my method is wrong
I said you have deleted the line that does that

11. Use your code on a short linked list with some values. Work the list - add and delete nodes, change the values, etc. Do it all. Good practice, anyway.

And keep printing up the new list, after you do each of these.

See for yourself what is the difference between your code, and the school's. Sometimes it's hard to believe that something is hot, until you get close enough to feel the heat. Then you know it's hot, and your mind opens up to accepting the idea that the object is indeed, hot.

12. why i get this warning
c|18|warning: assignment from incompatible pointer type|
Code:
```#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node *next;
}Node;

void what1(Node ** p,int num);
int main()
{

return 0;
}

void what1(Node ** p,int num){
Node *elt;
elt=(Node*)malloc(sizeof(Node));
elt->next=p;                                            //i get warning here
elt->value=num;

}```

13. Originally Posted by transgalactic2
why i get this warning
because you know better

14. Originally Posted by transgalactic2
why i get this warning
c|18|warning: assignment from incompatible pointer type|
What is the type of elt->next and the type of p on this line?
Code:
`elt->next=p;`

15. i understand my error p is node**
elt is node*

another question is:
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;
}```
Originally Posted by laserlight
The key to the linked list is on this line:
Code:
`elt->next=*p;`
This says that the node pointed to by elt now has a next pointer that points to the node pointed to by *p. In more graphical terms, this tongue twister is like this:

First, we have two pointers that point to nodes:
Code:
```*p --> [node #1]
elt --> [node #2]```
Now, we get elt's next pointer to point to what *p is pointing to:
Code:
`elt->next --> [node #1]`
This means that we now have two nodes linked together:
Code:
`[node #2] --> [node #1]`

Now, here's the catch. elt points to node #2, but elt itself is a local variable. When the function ends, elt will be destroyed. What to do?

We can choose to return elt, but in this case we choose to make *p point to what elt points to. As such, the caller now has a pointer to node #2
.
regarding the red marked part:
before the last step we have elt->next->*p

what happens to this structure after the red part
because as i see it when you say
"we choose to make *p point to what elt points to"
we get a circular linked list between the old and the new heads
??