in Programming edited by
2 votes
2 votes

Consider the following program:

int main()      int f1()        int f2(int X)               int f3()
{               {               {                           {
    f1();           return(1);      f3();                       return(5);
    f2(2);      }                   if(X==1)                }
    f3();                               return f1();    
    return(0);                      else    
}                                       return (X*f2(X-1));

Which one of the following options represents the activation tree corresponding to the main function?

in Programming edited by

1 comment

The tags for this question are wrong .Please remove the tags programming,programming in c,recursion and replace them with runtime-environment and compiler design.

1 Answer

3 votes
3 votes

The correct execution sequence is given in the above figure. inside main() we have $3$ function call as $f_1(),f_2(),f_3()$.

$f_1(),f_3()$ will return but $f_2()$ will take $x=2$ and evaluate it. when $X=2$ it will call $f_3()$ and else part. in next time when $x$ value became $1$ again it will call $f_3()$ and if part of given code. after that, it will return.

Option (A) is correct.