I have created a linked list struct in c
struct node{
int value;
struct node* next;
};
a method to add a node at the start of the list :
void addFirst(struct node **list, int value){
struct node *new_node = (struct node*) malloc (sizeof (struct node));
new_node->value = value;
new_node->next = *list;
*list = new_node;
}
This is the correct code. the problem is that the poineter struct node *list
You are passing can't be changed as it is a stack variable. If you change it to struct node **list
you are passing a pointer to the first node of the list. now you can change that to point to the new first node of the list.