我是使用Dev C++編譯
int main(int argc, char *argv[]) {
int a,b,c,d;
a=32;
b=(a++)*((++a)+(a++));
a=32;
c=((a++)+(++a))*(a++);
a=32;
d=(a++)+(a++)+(++a);
cout<<b<<endl;
cout<<c<<endl;
cout<<d;
return 0;
}
出來結果為
2178
2178
97
由答案推回原題目
b的結果似乎是33*(33+33)
c=(33+33)*33
d=32+32+33
想請問為什麼a++有32跟33兩種情況?
謝謝
出現的結果跟你不一樣,所以結論是這種用法並不具有可移殖性。
大家可以把下面的code拿去跑跑看,看結果是否一樣。
#include <iostream>
int p(int i, int j)
{
std::cout << j << "\'s item is " << i << '\n' ;
return i;
};
//print result
void pr(char c, int i)
{
std::cout << c << " = " << i << '\n' ;
};
int main()
{
int a,b,c,d ;
a=32;
b=p(a++,1)*(p(++a,2)+p(a++,3));
a=32;
c=(p(a++,1)+p(++a,2))*p(a++,3);
a=32;
d=p(a++,1)+p(a++,2)+p(++a,3);
pr('b',b);
pr('c',c);
pr('d',d);
return 0;
};
result :
1's item is 32
2's item is 34
3's item is 34
1's item is 32
2's item is 34
3's item is 34
1's item is 32
2's item is 33
3's item is 35
b = 2176
c = 2244
d = 100