请说明程序的执行方式,以及为什么会生成此类特定输出。
输出为
6 10 20
6 10 8
2 2 14
我的猜测可能是由于IN,OUT,INOUT参数引起的,但我并不是很了解
#include <iostream>
using namespace std;
void sunny(int&, int);
void cloudy(int, int&);
int temp;
int main()
{
int num1 = 6;
int num2 = 10;
temp = 20;
cout << num1 << " " << num2 << " " << temp << endl;
sunny(num1, num2);
cout << num1 << " " << num2 << " " << temp << endl;
cloudy(num1, num2);
cout << num1 << " " << num2 << " " << temp << endl;
}
void sunny(int& a, int b)
{
int w;
temp = (a + b) / 2;
w = a / temp;
b = a + w;
a = temp - b;
}
void cloudy(int u, int& v)
{
temp = 2 * u + v;
v = u;
u = v - temp;
}
答案 0 :(得分:0)
实际上输出是:
temp = (6 + 10)/2 = 8
w = 6/8 = 0 //This is because w is declared int, and int(6/8) = 0
b = 6 + 0 = 10
a = 8 - 6 = 2
我们可以看到以下步骤:
晴朗电话:
temp = 2 * 2 + 10 = 14
v = 2
u = 2 - 14 = -12 //This variable is doing nothing
因此,由于引用参数的原因,num1现在为2,并且由于其全局变量temp更改为8
多云通话:
isError$: Observable<boolean>;
ngOnInit() {
this.isError$ = this.store$.select(
ShipmentLookupStoreSelectors.selectShipmentLookupError
);
}
因此num2现在为2,原因与以前相同,而temp为14