C++参考文献6

以下C++程序的输出?

null

#include<iostream>
using namespace std;
int main()
{
int x = 10;
int & ref = x;
ref = 20;
cout << "x = " << x << endl ;
x = 30;
cout << "ref = " << ref << endl;
return 0;
}


(A)

x = 20
ref = 30

(B)

x = 20
ref = 20

(C)

x = 10
ref = 30

(D)

x = 30
ref = 30

答复: (A) 说明: ref是x的别名,所以如果我们改变其中一个,我们也可以看到另一个的变化。 这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享