GATE CS 2023 · Question 36 · Compiler Design · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer
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?
- (A) Tree with root main. main has three children, left to right: f1, f2, f3. The child f2 has two children: f3 and f2. That inner f2 has two children: f3 and f1. All other nodes are leaves.

- (B) Tree with root main. main has three children, left to right: f1, f2, f3. The child f2 has two children: f3 and f1. All other nodes are leaves.

- (C) Chain-shaped tree with root main. main has a single child f1. f1 has a single child f2. f2 has two children: f3 and f1.

- (D) Tree with root main. main has three children, left to right: f1, f2, f3. The child f2 has three children: f3, f2 and f1. All other nodes are leaves.

Answer
Answer (A)
Answer from the official GATE CS 2023 answer key.
The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes