高手,,,vc++问题呀?

来源:百度知道 编辑:UC知道 时间:2024/06/05 04:39:06
int j=5
j=(++j)+(++j)+(++j);等于几
运算原理
谢了
我算等不对呀
结果为22
不是21我算也是21
但运行结果为22

这个问题不是太清楚,我用程序论证了,可是不是太明白
程序如下:
#include<iostream.h>
int sun(int j)
{
++j;
cout<<j<<endl;
return j;
}
void main()
{
int j=5,a=0;
j=(j=sun(j))+(j=sun(j))+(j=sun(j));
//j=(++j)+(++j)+(++j);
//a+=++j;
//a+=++j;
//a+=++j;
cout<<j<<endl;
}
结果:
6
7
8
22

我想可能是计算的优先级问题吧~!
我曾经遇到过此问题,但不是这样式的,
我只知道C++和C语言的运算时的优先级和方向是有些是相反的.

#include<iostream.h>
#include<stdlib.h>
int main()
{
int j=5,a=0;
j=5;
cout<<j<<endl;
j=5;
cout<<j+(++j)<<endl;
j=5;
cout<<(++j)+(++j)<<endl;
j=5;
cout<<j+(++j)+(++j)<<endl;
j=5;
cout<<(++j)+(++j)+(++j)<<endl;
j=5;
cout<<(++j)+(++j)+(++j)+(++j)<<endl;
j=5;
cout<<(++j)+(++j)+(++j)+(++j)+(++j)<<endl;
system("