title: Insert at the back of a singly linked in C
body: <p>Below is my node struct declaration and my insert at the back function. In main, I declare a head node and point it to NULL. Then I call the function, and try to print out the value of the first node but my program stops. I still can't figure out what is wrong.</p>
  
  <pre><code>     typedef struct node {
           int val;
           struct node *next;
       } NODE;
  
       void insert_back(NODE *head, int val) {
       NODE *new = malloc(sizeof(NODE));
       new-&gt;val = val;
       new-&gt;next = NULL;
           if (head == NULL)
               head = new;
           else {
               NODE *p = head;
               while (p-&gt;next != NULL)
                   p = p-&gt;next;
               p-&gt;next = new;
           }
       }
  
  
       int main() {
           NODE *head = NULL;
           insert_back(head, 2);
           printf("%d", head-&gt;val);
       }
  </code></pre>