Java Reference
In-Depth Information
current function another function, say G , is called, the same mechanism applies:
First, local memory for storing all block variables declared in the function block
of G is allocated, and arguments are passed by value. Once G is completed, the
local memory allocated for its execution is released. These various levels of
nested function calls yield the function call stack .
static double G(double x)
double result;// local memory
result=Math.pow(x,2.5);
return result;
Binding:
Pass-by-value
x=25;
static F(double x)
double result;// local memory
result=1.0+G(x*x);
return result;
Binding:
Pass-by-value
x=5;
static void main(String [] arg)
double y;//local memory
y=F(5);
System.out.println(”y=”+y);
Function call stack
Figure 3.1 Illustrating the function call stack: The function variables are
allocated into the local memory stack and are thus not visible to other functions.
The pass-by-value mechanism binds the function arguments with the respective
expression values at calling time
Program 3.6 Illustrating the function call stack
class FunctionStack {
static double G( double x)
double result ;
result=Math.pow(x,2.5) ;
 
Search WWH ::




Custom Search