Not understanding the recursive function

int solve(int n)
{
if(n==0 or n==1)
return n;
int sum=0;

return sum+n+solve(n-1);

}

and

int solve(ll n)
{
if(n==0 or n==1)
return n;
int sum=0;

sum=sum+n;
return solve(n-1);

}

what is the difference in working of these two function, please tell me how call stack work of these two function work, please help i am totally confuses

hi @shivamgoel150 in the second code, you are calculating sum, but you are not returning it, so it wont be propogated to the final answer. If you simple return n in the base case, and return solve(n-1) for the recursive case, the final answer will remain as 0 or 1 only (whatever value you returned in the base case)

Whereas in the first code you are doing some modification to the asnwer returned from the recursive calls, you are actually adding sum to it, so it will be reflected in the final answer as well.