title: Find binary tree height
body: <p>I am trying to write a function to get the height of a binary tree. When I print the value of the <code>maxi</code> the value is what I expect but when the function returns the value, the value is always 0. Can someone tell what I am doing wrong here?     </p>
  
  <pre><code>int treeHeight(tree *p)
  {
      static int maxi=0;
      static int i=0;
      if(p==NULL)
      {
          return maxi;
      }
      else
      {
          if(p-&gt;left!=NULL||p-&gt;right!=NULL)
          {
              i++;
          }
          else
          {
              i++;
              if(maxi&lt;i)
              {
                  maxi=i;
              }
          }
          treeHeight(p-&gt;left);
          treeHeight(p-&gt;right);
          i--;
      }
  }
  </code></pre>