【发布时间】:2016-02-04 09:28:15
【问题描述】:
我不知道为什么结果是这样的?我预计是 15 50 5。 谁能帮我理解结果
#include<iostream>
#include<conio.h>
using namespace std;
int f(int &a, int &b)
{
int m = a;
int n = b;
a = a*b;
b = a / b;
return n + m;
}
int main()
{
int x = 10;
int y = 5;
cout << f(x, y) << " " << x << " " << y;
_getch();
return 0;
}
//why is the result like this?
【问题讨论】:
-
结果怎么样?
-
我不知道你得到了什么,但预期是:15 50 10
-
vs 2015 得到的结果是 15 10 5。
-
@Kasra 点击链接。
-
问题是
f(x, y)更新x和y。我们不知道输出是显示旧值还是新值。那是未指定的。
标签: c++