在下面的代码中,为什么交换函数以两种方式工作,通过将值传递为swap(x,y)和swap(&x,&y).
int main(){
int x, y;
cout << "Enter the values of x and y: ";
cin >> x >> y;
swap(x, y);
cout << "\nSwapped values are, x: " << x << " & y: " << y <<"\n";
return 0;
}
void swap(int *a, int *b){
int s;
s = *a;
*a = *b;
*b = s;
}
Run Code Online (Sandbox Code Playgroud)