****************************************
* LUG meet on 12 Jan. 2003 @ VJTI
****************************************

HI friends 
I was experimenting with a common c factorial problem
when I got a totally unexpected result.

here is the program

# include <stdio.h>
main(){
   int fact;
   int x;
   fact=factorial(6);
   printf ("%i\n",fff());
}


int factorial(int x){
   if(x>1) return(x*factorial(x-1));
}

int fff () {
   ;
}


Naturally I was expecting  1 as the answer. But I am getting the answer 720 
which is 6!.

If I comment the 5th line fact=factorial(6); I am getting the expected result 
"1".

The normal explanation for this is memory leak. Can anyone please tell me what 
is happening and are you too getting the same result.

I am using redhat linux 7.3 with gcc 2.96

regards
Abhijeet D Mhatre



--
_______________________________________________

http://mm.ilug-bom.org.in/mailman/listinfo/linuxers



Reply via email to