Code to count number of leaves of a tree?
Using this recursive algorithm is indeed a correct way. But your code is wrong, and it could use some improvements.

First of all, you are using a pointer for head so you should use -&gt; instead of . to access the left and right element.

Then, using a static variable is not the cleanest way to store the result. You could use the recursion and simply return the result, like so:

int Count_leaf(Tree* head)
{
    if(head-&gt;left == NULL &amp;&amp; head-&gt;right == NULL)
        return 1;
    else
        return Count_leaf(head-&gt;left) + Count_leaf(head-&gt;right);
} 


Finally, you should check if the tree is empty before starting any counting. You can add a simple condition at the start of your fonction to do that:

if(head == NULL)
    return 0;


Here is the final program:

int Count_leaf(Tree* head)
{
    if(head == NULL)
        return 0;

    if(head-&gt;left == NULL &amp;&amp; head-&gt;right == NULL)
        return 1;
    else
        return Count_leaf(head-&gt;left) + Count_leaf(head-&gt;right);
}