I was trying to write a function which will take an integer and return it's factorial. I used c++ language. The actual code should be:
int f(int x)
{
if(x==0)
return 1;
else if(x>=1)
return x=x*f(x-1);
else
return 1;
}
This is correct form. But,
int f(int x)
{
if(x>1)
x=x*f(x-1);
}
this also works even I didn't mentioned any 'return'. Also when the recursion goes to base case, there is nothing to return! So, how does it works actually ? :o