C++基础问题a

来源:百度知道 编辑:UC知道 时间:2024/06/15 21:29:51
下面的程序输出结果我自己算的是16,而执行出来是0,为什么?
#include <iostream.h>
int fun2(int a,int b)
{
int c;
c=a*b%3;
return c;
}
int fun1(int a,int b)
{
int c;
a+=a;b+=b;c=fun2(a,b)+fun2(a,b);
return c*c;
}
void main()
{int x=11,y=9;
cout<<fun1(x,y)<<endl;
}

参数刚传进去的时候(fun1里边)a=11,b=9.
执行a+=a;b+=b;后a==22;b==18;
c=fun2(a,b)+fun2(a,b); 的两个fun2(a,b)调用动作是一样的,由于数据域的缘由,即两个fun2(a,b)==22×18 % 3 == 0;弄到最后c的值就是个0,这样一切就明了啦~~~

0
你是怎么算的~