Int a1=300, a2=400;
Void sub1 (int x, int y)
{a1=x;
X=y;
Y=a1;
}
Int main ()
{
Int a3=100, a4=200;
Sub1 (a3, a4);
Sub1 (a1, a2);
Printf (" % d, % d, % d, % d \ n ", a1, a2, a3, a4);
return 0;
}
CodePudding user response:
Sub1 exchange, this function is to suggest using swap as a function name, or swap_int,Exchange, the actual result is can't because the parameter is the value transfer, arguments a3, a4 with sub1 in x, y are independent of each other, sub1 function in the exchange of x, y, but the two values is the function of internal variables, the end of the function call will be automatically released and therefore does not affect the a3, a4 values, similarly also is a1, a2
CodePudding user response:
To realize the exchange value is not enough, as the upstairs said, the address can be achieved,