title: Passing typedef structure as call by reference in C
body: <p>I am trying to create a linked list in C and my code is as below.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  typedef struct node {
      int data;
      struct node *next;
  }node_t;
  
  
  void insert_into_list(node_t *,int);
  void print_list(node_t *);
  node_t *create_node(int );
  
  
  
  void insert_into_list(node_t *head, int value){
      node_t *temp ;
      temp = create_node(value);
      if(head == NULL){
          printf("Inserting node for the first time\n");
          head = temp;
      }else {
          head-&gt;next = temp;
      }
  
  }
  void print_list(node_t *head){
      node_t *current = head;
      while(current!=NULL){
          printf("%d-----&gt;",current-&gt;data);
          current = current-&gt;next;
      }
      printf("NULL");
  }
  node_t *create_node(int value){
      node_t *new_node = malloc(sizeof(node_t));
      if(new_node==NULL){
          printf("Memory allocation failed for the list creation. :(");
          return NULL;
      }
      new_node-&gt;data = value;
      new_node-&gt;next = NULL;
      return new_node;
  }
  
  
  int main(int argc, char *argv[]) {
      node_t *head = NULL;
      insert_into_list(head,10);
      if(head==NULL){
          printf("Still head is NULL :(");
      }else{
          printf("Head is not NULL:)");
      }
      print_list(head);
      return 0;
  }
  </code></pre>
  
  <p>In <code>main</code>, I am calling insert_into_list and even after successful memory allocation, i am not able to get the head value with the newly created node. Still showing the value as NULL.</p>
  
  <p>I have debugged with gdb and found that upto below code, head is not NULL </p>
  
  <pre><code>printf("Inserting node for the first time\n");
  head = temp;
  </code></pre>
  
  <p>I thought I am passing by reference and expected the value to get reflected in the caller function.</p>
  
  <p>Please correct me. </p>