This is a small function I have written to check whether an integer is a prime or not:
int prime(int x, int y = 2)
{
if(y <= x/2)
{
if((x % y) == 0)
return 0;
}
else
return 1;
return prime(x, ++y);
}
Now, I compile it with visual studio 2012, and if i give it a large value such as 105943, a stack overflow error occurs and the code breaks. Now, is this function not tail recursive? If so then a stack shouldn't be maintained for the recursive calls, and an overflow should not occur?
What am I not getting here exactly?
-O, gcc needs-O2to make a loop of it)