title: How do I know if I'm generating undefined behaviour
body: <p>This all could be because I'm just not understanding some basic things about what undefined behaviour is or how it manifests itself.
  The code in the snippet below is what I've got so far, it creates a linked list. I used the online IDE <a href="https://ideone.com/JNfXIY#stdin" rel="nofollow noreferrer">IDEone</a> run it.</p>
  <p>The main thing I'm not understanding is whether <code>printf(&quot;\nhead value at the end = %d&quot;, (*head).value);</code> just above <code>return</code> in the <strong>main</strong> function is producing UB or not.</p>
  <p>That line prints out a <strong>0</strong>, I expect UB since the <strong>clean_list</strong> function frees memory previously allocated to each list node (unless I'm doing that function wrong).</p>
  <p>Shouldn't I get an error or something like that about undefined behaviour during runtime, or at the very least should the program not crash? Or could it be IDEone's safety measures that prevent UB? Or am I just not understanding something with regards to UB?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct node {
      int value;
      struct node* next;
  };
  typedef struct node node_t;
  
  node_t* create_linked_list(unsigned int number_of_nodes) {
      node_t* head = NULL;
      
      for (unsigned int i = 1; i &lt; number_of_nodes + 1; ++i) {
          node_t* node = malloc(sizeof(node_t));
          node-&gt;value = i;
          node-&gt;next = head;
          head = node;
      }
  
      return head;
  }
  
  void print_list(node_t* head) {
      node_t* temp = head;
      
      while (temp != NULL) {
          printf(&quot;%d - &quot;, temp-&gt;value);
          temp = temp-&gt;next;
      }
  
      printf(&quot;\n&quot;);
  }
  
  void clean_list(node_t* head) {
      node_t* current = head;
      
      while (current != NULL) {
          node_t* temp = current;
          current = current-&gt;next;
          free(temp);
      }
      
      printf(&quot;\nclean_list complete \n&quot;);
  }
  
  int main(void) {
      node_t* head = create_linked_list(15);
      
      printf(&quot;head address at beginning = %p\n&quot;, head);
      printf(&quot;head value at the beginning = %d\n\n&quot;, (*head).value);
      
      // Prints a list from 1 to 15.
      print_list(head);
      
      clean_list(head);
      
      printf(&quot;\nhead address at the end = %p&quot;, head);
      printf(&quot;\nhead value at the end = %d&quot;, (*head).value);
      
      return 0;
  }
  </code></pre>