单选题:下列代码实现x和y值的交换,fun函数的参数应该为( )
下列代码实现x和y值的交换,fun函数的参数应该为( )
c++
void fun(......) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}
A.int a,int b
B.int& a, int& b
C.int* a, int* b
D.const int& a, const int& b
answer:B
c++
void fun(......) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}
A.int a,int b
B.int& a, int& b
C.int* a, int* b
D.const int& a, const int& b
answer:B