# Include <stdlib. h>
# Include <stdio. h>
Void swap1 (int x, int y)
{
Int temp;
Temp = x;
X = y;
Y = temp;
}
Void swap2 (int * x, int * y)
{
Int * temp;
Temp = x;
X = y;
Y = temp;
}
Void swap3 (int * x, int * y)
{
Int temp;
Temp = * x;
* X = * y;
* Y = temp;
}
Void swid (int a [], int B [])
{
Int temp;
Temp = a [0];
A [0] = B [0];
B [0] = temp;
}
Void swap5 (int a [], int B [])
{
Int temp;
Temp = *;
* A = * B;
* B = temp;
}
Int main ()
{
Int x, y;
X = 4;
Y = 3;
Swap1 (x, y );
Printf ("swap1: x: % d, y: % d \ n", x, y); // The parameter value cannot be exchanged, in the past, it was a copy without changing x, y in the main function.
Swap2 (& x, & y );
Printf ("swap2: x: % d, y: % d \ n", x, y); // cannot be exchanged. The function only switches the address, the content pointed to by the address is not exchanged
Swap3 (& x, & y );
Printf ("swap3: x: % d, y: % d \ n", x, y); // You can exchange the content pointed to by the address.
Swap4 (& x, & y );
Printf ("swap4: x: % d, y: % d \ n", x, y); // exchange the content pointed to by the address
Swap5 (& x, & y );
Printf ("swap5: x: % d, y: % d \ n", x, y); // exchange the content pointed to by the address
Return 0;
}
Swap1: x: 4, y: 3
Swap2: x: 4, y: 3
Swap3: x: 3, y: 4
Swap4: x: 4, y: 3
Swap5: x: 3, y: 4
From bored blogs