-->
当前位置:首页 > Eng > 正文内容

单选题:下列哪个代码能够实现x和y值的交换( )

Luz2年前 (2022-11-19)Eng496
下列哪个代码能够实现x和y值的交换( )




A.c++
void fun(int a,int b) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}

B.c++
void fun(int&a,int&b) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}

C.c++
void fun(int* a,int* b) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}

D.c++
void fun(const int&a,const int&b) {
int x = a;
a = b;
b = x;
}
int main() {
int x = 1, y = 2;
fun(x, y);
cout << x << ","<<y << endl;
return 0;
}



answer:B

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。