CALL-BY-REFERENCE Under call-by-reference, a formal parameter becomes a synonym for the the location of an actual parameter. 传实际参数的地址给形参,形参成了该地 址的同义词
CALL-BY-REFERENCE Under call-by-reference, a formal parameter becomes a synonym for the the location of an actual parameter. 传实际参数的地址给形参,形参成了该地 址的同义词
Example: procedure swapvar x, y: integer) var z: integer; begin 2:=xX:=yy:=2 end A call swap(i, A[i]) is implemented as follows: make the location of x the same as that of i make the location of y the same as that of ali; 2:xX:=yy:=2 If i is 2 and a[2] is 99, the effect of these statements s z:=2;i:=99;A[2]:=z Thus, these assignments exchange the values of i and A[2]
Example: procedure swap(var x, y : integer); var z : integer; begin z := x; x := y; y := z; end A call swap(i,A[i]) is implemented as follows: make the location of x the same as that of i; make the location of y the same as that of A[i]; z := x; x := y; y := z; If i is 2 and A[2] is 99, the effect of these statements is z := 2; i := 99; A[2] := z; Thus, these assignments exchange the values of i and A[2]
The only parameter-passing method in C is call-by-value; however the effect of call-by-reference can be achieved using pointers. Example: void swap〔int*xint为){ int Zi Z=XX=为为y=z A call swap &a, &b) is implemented as follows: pX= &a y=&b; PX=和v These assignments exchange the values of a and b
The only parameter-passing method in C is call-by-value; however, the effect of call-by-reference can be achieved using pointers. Example: void swapc(int *px, int *py) { int z; z = *px; *px = *py; *py = z; } A call swapc(&a, &b) is implemented as follows: px = &a; py = &b; z = *px; *px = *py; *py = z; These assignments exchange the values of a and b
CALL-BY-VALUE-RESULT 值结果传递 Call-by-value-resultis also known as copy/copy-out(传入传出机制) because (1,the actuals are initially copied into the formals and(2)the formals are finally copied back to the actuals 进入时传值,退出反馈结果
CALL-BY-VALUE-RESULT 值结果传递 Call-by-value-result is also known as copy-in/copy-out(传入/传出机制) because (1.) the actuals are initially copied into the formals and (2.) the formals are finally copied back to the actuals. 进入时传值,退出反馈结果