title: Difference between Node->next!=NULL and Node!=NULL in C
body: <p>This function doesn't work if I make a modification in <code>while</code> condition and change <code>temp != NULL</code> to <code>temp-&gt;next = NULL</code>. Why is that?</p>
  
  <pre><code>void Print() {
       printf("\n");
       printf("The Library data is as follows: \n");
       struct Node *temp = head; // where head is a global variable
       printf("\n");
       while (temp != NULL) {
           printf("%25s", temp-&gt;name);
           printf("%25s", temp-&gt;author);
           temp = temp-&gt;next;
           printf("\n");
       }
  }
  </code></pre>
  
  <p>Plus if I modify the <code>while</code> loop condition under <code>else</code> block, from <code>temp1-&gt;next = NULL</code> to <code>temp1 != NULL</code>, it doesn't work. Why is that?</p>
  
  <pre><code>void Insert(char q[50], char r[50]) {
      struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
      temp-&gt;next = NULL; // Since we are adding a node to the end, we are linking it to NULL.
      strcpy(temp-&gt;name, q); // copying the contents of "q" to "temp-&gt;name"
      strcpy(temp-&gt;author, r); // same
      if (head == NULL) {
          head = temp;
      } else {
          struct Node *temp1 = head;
          while (temp1-&gt;next != NULL)
              temp1 = temp1-&gt;next;
          temp1-&gt;next = temp;
      }
  }
  </code></pre>