edited by
7,945 views
8 votes
8 votes

Consider the following program:

int main() 
{
    f1 ();
    f2(2);
    f3();
    return (0);
}

 

int f1 ()
{
    return(1);
}

 

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

 

int f3 ()
{
    return (5);
}

 

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

edited by

1 Answer

9 votes
9 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.

Answer:

Related questions