c++ passing by reference in recursion
<pre><code>bool roottoleafsumequaltox(BinaryTreenode&lt;int&gt;* root, int &amp;x)
{
    if(root == NULL)
    {
        return (x==0);
    }
    else
    {
     bool ans = false;
     x = x - root-&gt;data;

     if(x == 0 &amp;&amp; root-&gt;left == NULL &amp;&amp; root-&gt;right == NULL)
     {
       return true;
     }

     if(root-&gt;left)
      ans = ans || roottoleafsumequaltox(root-&gt;left, x);

     if(root-&gt;right)
      ans = ans || roottoleafsumequaltox(root-&gt;right, x);

     return ans;
   }
}
</code></pre>

<p>It has to return whether the root to leaf sum is equal to a given number x. I think the problem lies in passing by reference and I am not able detect it...
It always gives false as the answer, even if it is true!</p>