title: If Statement in linked list not working as expected
body: <p>So currently i have an <code>if</code> statement in the <code>GetNth</code> function that im trying to test. but when i inserted a <code>printf</code> function, it made me notice that it goes through the <code>if</code> statement even if the condition is not met, however, when i remove the <code>printf</code> statement the program works flawlessly. any explanation would be appreciated. </p>
  
  <p>Notice! This is not my code, im trying to study linked lists and was changing the code around trying to learn!</p>
  
  <p>The Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  
  /* Link list node */
  struct node
  {
      int data;
      struct node* next;
  };
  
  /* Given a reference (pointer to pointer) to the head
   of a list and an int, push a new node on the front
   of the list. */
  void push(struct node** head_ref, int new_data)
  {
      /* allocate node */
      struct node* new_node =
      (struct node*) malloc(sizeof(struct node));
  
      /* put in the data  */
      new_node-&gt;data  = new_data;
  
      /* link the old list off the new node */
      new_node-&gt;next = (*head_ref);
  
      /* move the head to point to the new node */
      (*head_ref)    = new_node;
  }
  
  /* Takes head pointer of the linked list and index
   as arguments and return data at index*/
  int GetNth(struct node* head, int index)
  {
      struct node* current = head;
      int count = 0; /* the index of the node we're currently
                      looking at */
      int a;
      while (current != NULL)
      {
          if (count == index)
              return(current-&gt;data);
              a = current-&gt;data;
              printf("\n Testing If in linked list, should bring same desired value which is 4 %d \n ",a);
          count++;
          current = current-&gt;next;
      }
  
      /* if we get to this line, the caller was asking
       for a non-existent element so we assert fail */
      assert(0);
  }
  
  /* Drier program to test above function*/
  int main()
  {
      /* Start with the empty list */
      struct node* head = NULL;
  
      /* Use push() to construct below list
       1-&gt;12-&gt;1-&gt;4-&gt;1  */
      push(&amp;head, 1);
      push(&amp;head, 4);
      push(&amp;head, 1);
      push(&amp;head, 12);
      push(&amp;head, 1);
      if (head != NULL)
      {
  
      }
      /* Check the count function */
      printf("Element at index 3 is %d", GetNth(head, 3));
      getchar();
  }
  </code></pre>