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

On Wed, 18 Dec 2002, Abhijeet D Mhatre wrote:

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

unexpected?

> # include <stdio.h>
> main(){

return type defaults to int

>    int fact;
>    int x;
>    fact=factorial(6);
>    printf ("%i\n",fff());

so where is the statement that returns an int?

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

what happens if x<=1?  what is the return value then?

> }
> 
> int fff () {
>    ;
> }

and what is this supposed to return?  the printf will print the return 
value of this function, but this function doesn't return anything.

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

pray tell us why you expected this so naturally.


Philip

-- 
You scratch my tape, and I'll scratch yours.



-- 
_______________________________________________

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



Reply via email to