#include <iostream>
using namespace std;
void f(int& p)
{
p += 2;
}
int main()
{
int x = 10;
f(x);
int y = x + 1;
f(y);
cout << "x is " << x << endl;
cout << "y is " << y << endl;
system("PAUSE");
return 0;
}
现在的答案是,x
是12和y
为15C++输出搞清楚问题
我有点明白也许这x
是12.要说明,如果我这样做是正确的,作为
void f (int &p)
{
p += 2;
}
和int x = 10
所以你10 += 2
其是12,从而x
是12.
卜T I不明白为什么y
是15
是不是因为我用12 x
为int y = x + 1
所以它的12 + 1
是13,然后13 += 2
这是15?
非常感谢! :) – Nina555