You are on page 1of 64

test::i

main::i run-time
stack ptr

test::count static var


ptr
count
main( ) {
int a = 6;
int b = 4;
Cswap(a, b);
// a = 6
// b = 4
}
temp=6
d=4 6

Cswap(int c, int d) { c=6 4


int temp = c;
b=4
c = d; Cswap stack
d = temp; a=6
}
main stack
caller( ) {
int a ;
int b ;
foo(a, b);
// a = 6
// b = 4
}

d =4
foo(int c, int d ) { c =6
c=6;
b
d=4;
foo stack
} a

caller stack
integer a = 3 ;
integer b = 1 ; temp =3
integer k[10] ;
k[3] = 7; b=1
b=7 33
swap(a, b); swap stack a=3 17
swap(b, k[b]);

k[3] =7 3
procedure swap(a : in out integer,
b : in out integer) is k[2]
temp : integer; k[1]
begin
k[0]
temp := a ;
a := b ; b=1 3 7
b := temp ; a=3 1
end swap;
main stack
caller( ) {
int a = 3 ;
int b = 1 ; temp=3
swap(&a, &b) ; d=2004
d=2020
}
c=2000
c=2004
2024
2020 swap stack

2016
swap(int *c, int *d ) {
2012
temp = *c;
*c = *d ; 2008
*d = temp ; b=1 3
} 2004
a=3 1
2000
caller stack point
, i nin ve hangi a[i] ( )
int Plus (int num) { int main( ) {
return num + num ; int Result ;
} int (*pF)(int) ;

int Square (int num) { pF = Plus;


return num * num; Result = Execute(3, pF);
} // =6

void Execute(int seed, pF = Square;


int (*pF)(int)) { Result = Execute(3, pF);
return pF(seed) ; // =9
} }
function sub1 () { Shallow Binding the reference
var x; environment of the call statement is
function sub2 () {
alert(x); passed to the subprogram
}; X=4
function sub3 () {
var x; Deep Binding the environment of
x = 3; the definition of the passed
sub4 (sub2);
};
subprogram
function sub4 (subx) { X=1
var x;
x = 4; Ad Hoc Binding the environment
subx (); of the call statement that passes
};
x = 1;
the subprogram as an actual
sub3 (); parameter
}; // JavaScript
X=3

You might also like