title: Comparing int to NULL in C - is this tutorial incorrect?
body: <p>I'm looking at this tutorial <a href="http://www.learn-c.org/en/Binary_trees" rel="nofollow noreferrer">http://www.learn-c.org/en/Binary_trees</a> and in the insert function it compares an int to NULL. It seems to run fine on the tut site but it didn't work for me and my research tells me it should not work. My code is below. </p>
  
  <ol>
  <li>Am I wrong here or is the tutorial wrong? </li>
  <li><p>If the tutorial is wrong is there any way to dynamically set the value for the first node of the BST? I thought about checking if left and right were both null but that would just keep resetting the first node. Having a third pointer for the value of the node seems wasteful but maybe it's the only way? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;malloc.h&gt;
  struct bstNode {
      int val;
      struct bstNode *left;
      struct bstNode *right;
  };
  
  int insert(struct bstNode *head, int val);
  
  void printDFS(struct bstNode *head);
  
  int main() {
      struct bstNode *bstTree = malloc(sizeof(struct bstNode));
      insert(bstTree, 8);
      insert(bstTree, 5);
      insert(bstTree, 98);
      insert(bstTree, 2);
      insert(bstTree, 15);
      insert(bstTree, 65);
      insert(bstTree, 15);
      printDFS(bstTree);
  }
  
  int insert(struct bstNode *head, int val) {
      //This is the problem statement, it contains random data when I debug as it's uninitialized
      if (head-&gt;val == NULL) {
          head-&gt;val = val;
          return 0;
      }
  
      if (val &lt; head-&gt;val) {
          if (head-&gt;left != NULL) {
              return insert(head-&gt;left, val);
          } else {
              head-&gt;left = malloc(sizeof(struct bstNode));
              head-&gt;left-&gt;val = val;
              return 0;
          }
      } else {
          if (head-&gt;right != NULL) {
              return insert(head-&gt;right, val);
          } else {
              head-&gt;right = malloc(sizeof(struct bstNode));
              head-&gt;right-&gt;val = val;
              return 0;
          }
      }
  }
  
  void printDFS(struct bstNode *head) {
      if (head-&gt;left != NULL) printDFS(head-&gt;left);
      printf("%d ", head-&gt;val);
      if (head-&gt;right != NULL) printDFS(head-&gt;right);
  }
  </code></pre></li>
  </ol>