question archive For the following nested definitions of functions f1 and f2, how is the nesting link of each activation record of the called function set? Here it is assumed that random() function generates a random integer
Subject:Computer SciencePrice:3.86 Bought8
For the following nested definitions of functions f1 and f2, how is the nesting link of each activation record of the called function set? Here it is assumed that random() function generates a random integer.
function f1()
{
int x1;
function f2()
{
int x2 = random();
if x1 - x2 <=0
return x1 + x2;
else
f2();
}
}
Activation record stack keeps track of all the functions that have been called . Here we use stack which is first in last out (FILO) data structure.
Activation record keeps all the information about a function call including parameters, local varisbles and return values.
So when one function calls a function , which in turns calls another function , which calls yet another function , all these information about function are stored in activation stack.
In the above program we first call function f1() then with in its body we call another function f2() .
f2() can recursively call itself if x1-x2>0 . All these calls are stored in activation stack
Please see the attached file for the complete solution