我不知道为什么结果是这样的?我预计15 50 5

时间:2016-02-04 09:28:16

标签: c++

我不知道为什么结果是这样的?我预计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?

1 个答案:

答案 0 :(得分:0)

  • 只需按照以下方式调用您的函数:

    int a = f(x, y);
    cout << a << " " << x << " " << y;