In C this code works, here I did't use return while calling function recursively. It gives correct output
int gcd(int a, int b)
{
if(b == 0)
return a;
gcd(b, a % b);
}
But, If I write same code in python this code returns None (I think value should be returned from the return statement inside if condition)
def gcd(a, b):
if b == 0:
return a
gcd(b, a % b)
To make this code work , I have to add return
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
but why? What is under the hood difference between code execution in C and Python? code in C also works if I add an extra return while calling recursively, Why doesn't it throws an error?