Formal parameter: Formal parameters
Arguments: Actual parameters
Pass Value:
copy The value of the argument to the parameter,
Modifying a parameter within a function does not affect the argument.
Transfer address:
Pointer pass-through value, parameter is a pointer to the address of the actual parameter
When you point to a parameter, the action is equivalent to the argument itself
#include <iostream>//Swap Location//"Value Call"voidSwap_value (intXinty) {inttemp =x; X=y; Y=temp;}//"Reference call 1", formal parameter: Pass the address, get the value (*)voidSwap_p (int*x,int*y) {inttemp = *x; *x = *y; *y =temp;}//"Reference Call 2", formal parameter: Pass the value, followed by the addressvoidSWAP_ADDR (int&a,int&b) {inttemp =A; A=b; b=temp;} Main () {intx =0; inty =1; printf ("x =%d, y =%d\n", x, y); Swap_value (x, y); printf ("after a value call: x =%d, y =%d\n", x, y); Swap_p (&x, &y); printf ("after the address call: x =%d, y =%d\n", x, y); Swap_addr (x, y); printf ("Pass-through address is called after: x =%d, y =%d\n", x, y);}
x = 0, y = 1 after the call: x = 0, y = 1 after the address call: x = 1, y = 0 value after address call: x = 0, y = 1
C Language: Pass the value, pass the address