help in recursion

void myFunc (int x)
{
if (x > 0)
myFunc(--x);
printf("%d, ", x);
}
int main()
{
myFunc(5);
return 0;
}

can any one explain this works, as 5 is passed to myfunc it decrement until reaches 1 and as it reached zero the if fails and printf prints 0, that wt after that, i am confused.... . thanks
If you need to print all values less or equal to x starting from zero then the function will look the following way

1
2
3
4
5
void myFunc( int x )
{
   if ( 0 < x ) myFunc( x - 1 );
   if ( !( x < 0 ) ) printf( "%d, ", x );
}

thanks but when i compile it the o/p is 0 0 1 ......
how come that..
Topic archived. No new replies allowed.