GeekInterview.com
  I am new, Sign me up!
 
Home C
 

How does the function call within function get evaluated?

 
Category: C
Comments (0)


Whenever we have more than one function which is called for a finite number of times then such a function gets evaluated from inside out.


Let us understand 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


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.


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 the outermost call is reached and thus value of 90 is returned which gets printed.



Read Next: What is difference between call by value and call by reference in function?



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape