in Programming in C recategorized by
631 views
0 votes
0 votes

What will be the return value of the below function, if it is called a sample(4)? 

int sample(int x){

    if( x == 0 || x ==2) return 1;

    return (sample(--x) * (x--));

}

 

in Programming in C recategorized by
631 views

4 Comments

Hello @DebSujit please check you Linkdin message section !

1
1

@DebSujit it is compiler dependent but not compiler defined. So you cannot guarantee that gcc will always give the same result. Such codes are not meant to be written by half a decent programmer and similarly won't be asked in any good exams except may be to check undefined behaviour knowledge. 

3
3

@gatecse Ah correct! Got it sir.

1
1

Please log in or register to answer this question.