Suppose we have more than one function called finite number of times then the function gets evaluated from inside out. Let us see this concept with an example.
For instance consider a function sample called within it 4 times as given in program below:
main()
{
int a=50;
a=sample(a=sample(a=sample(a=sample(a))));
printf(“%d”,a);
}
sample(a1)
int a1;
{
a1= a1+10;
return(a1);
}
Output of the above program is
90
Here the function sample gets evaluated from inside out. In other words the innermost call gets evaluated first followed by next outer function call and so on till the outermost function call.
So here first innermost function call of sample(a) gets called with value of a as 50 and evaluated and the result namely 60 is returned with which the next outer call sample gets called with value of 60 and returns the value 70 and proceeded till eth outermost call is reached and thus value of 90 is returned which gets printed.
How does the function call within function get evaluated?
Suppose we have more than one function called finite number of times then the function gets evaluated from inside out. Let us see this concept with an example.
For instance consider a function sample called within it 4 times as given in program below:
Output of the above program is
Here the function sample gets evaluated from inside out. In other words the innermost call gets evaluated first followed by next outer function call and so on till the outermost function call.
So here first innermost function call of sample(a) gets called with value of a as 50 and evaluated and the result namely 60 is returned with which the next outer call sample gets called with value of 60 and returns the value 70 and proceeded till eth outermost call is reached and thus value of 90 is returned which gets printed.
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin
This Question is not yet answered!
Related Answered Questions
Related Open Questions