Question: I am trying to add nodes in a linked list, passing the pointer of pointer, accessing the member (\*list) -> next gives a segmentation fault. Can someone point out the mistake, thanks in advance. The code is

```
void initializeList (node ** head, int data)
{
    *head = malloc (sizeof (node));
    (*head)-> member = data;
    (*head)-> next = NULL;
}

void addNode(node ** list, int data)
{
    node * newNode = NULL;
    newNode = malloc (sizeof (node));
    while (*list->next!= NULL) 
    {
        *list= (*list) -> next;
    }
    newNode -> member = data;
    newNode -> next = NULL;
    (*list) -> next = newNode;
}

void main ()
{
    node * head = NULL;
    initializeList (&head, 5);
    addNode(&head, 6);
}

```

Answer: 
You should not dereference a NULL pointer, otherwise as expected you get Seg Fault.

Here's the problem:

```
while (*list != NULL)
    {
    *list= (*list) -> next;
    }
newNode -> member = data;
newNode -> next = NULL;
(*list) -> next = newNode;

```

`*list` is NULL after while loop.  

And you are doing `(*list) -> next = newNode;`
newNode points to NULL after the loop
You cannot set its member and next value
use 
 while(\*list->next!= NULL)

which ensures that you are not dereferencing NULL