title: How is the recursive function returning 33?
body: <p>I have been stuck on this one for hours now</p>
  
  <p>This is the code that I am not able to get a hold of :</p>
  
  <pre><code>before recursive call sum value8  
  before recursive call sum value12 
  before recursive call sum value12  
  before recursive call sum value14 
  after recursive call sum value14  
  after recursive call sum value33 
  after recursive call sum value33  
  after recursive call sum value33  
  sum value in main33
  </code></pre>
  
  <p><br /> </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int foo(int n,int sum)
  {
      int k=0,j=0;
  
      if(n==0) return sum;
  
      k=n%10;
      j=n/10;
      sum+=k;
      printf("before recursive call sum value%d\n",sum);
  
      sum=foo(j,sum);
  
      printf("after recursive call sum value%d\n",sum);
  }
  
  int main()
  {
      int a=2048,sum=0;
      sum=foo(a,sum);
  
      printf("sum value in main%d\n",sum);
  }
  </code></pre>
  
  <p>The output is also present in the code.</p>
  
  <p>I have traced the function calls using a stack and I expected a value of 14 to be returned to the calling function(main()) but I am getting an output of 33 which I find difficult to understand.</p>
  
  <p><strong>Even If I assume I traced the recursion wrong somewhere, aren't all digits returned at any point of time even so how can their sum be 33 which is odd?</strong></p>
  
  <p>Any help regarding this would be appreciated. </p>