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 :
All is good, but in the void addFirst(struct node *list, int value)
function the list
is passed by value. Which means that a pointer is being copied and assignment of a new address to that pointer inside addFirst
function is not visible to the caller of addFirst
. To solve it, you have to either pass a pointer by pointer (struct node **
) or make it a return value and require a caller to use it as a new "head".
And don't forget ;
after a struct declaration.