Skip to main content

GATE CSE 2023Compiler Design › Runtime Environments & Parameter PassingVerified

GATE CSE 2023 PYQ: Consider the following program: int main () { f1 (); f2 ( 2 ); f3 (); return ( 0 ); } int f1 () { return ( 1…

Consider the following program:

  1. int main()
  2. {
  3. f1 ();
  4. f2(2);
  5. f3();
  6. return (0);
  7. }

 

  1. int f1 ()
  2. {
  3. return(1);
  4. }

 

  1. int f2 (int X)
  2. {
  3. f3();
  4. if (X==1)
  5. return f1 ();
  6. else
  7. return (X * f2 (X - 1));
  8. }

 

  1. int f3 ()
  2. {
  3. return (5);
  4. }

 

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

  1. A

    GATE CSE 2023 Runtime Environments & Parameter Passing diagram: Consider the following program: int main () { f1 (); f2 ( 2

    Correct answer
  2. B
    GATE CSE 2023 Runtime Environments & Parameter Passing diagram: Consider the following program: int main () { f1 (); f2 ( 2
  3. C
    GATE CSE 2023 Runtime Environments & Parameter Passing diagram: Consider the following program: int main () { f1 (); f2 ( 2
  4. D

    GATE CSE 2023 Runtime Environments & Parameter Passing diagram: Consider the following program: int main () { f1 (); f2 ( 2

Answer

(A)

Approach

Trace the actual function calls in execution order and build the activation tree. Then compare each option with the expected tree.

Tracing the call sequence gives exactly the tree shown in option A.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.