一个简单的C++有关问题,高手指教

一个简单的C++问题,高手指教
一个简单的C++问题
#include <iostream>
using   namespace   std;
int   main()
{
int   a[5]={1,2,3,4,5};
int   *p=a;
cout < <*p < < "   " < <*p++ < <endl;
return   0;
}
怎么输出是2   1   呀。

------解决方案--------------------
先送入缓冲区,缓冲区相当于一个栈空间,自加运算符自右向左结合
1
——
2
——
再从缓冲区顶部输出
------解决方案--------------------
同意楼上的,C++编译器读运算语句是从右至左的(我只说C++的,其他的语言是不是这样就不知道了……)^^
------解决方案--------------------
楼上不太正确吧。
实际应该是这样的:
((((cout < <*p) < < " ") < <*p++) < <endl);

计算时,先计算 *p++,这里,*p 是 1,但是 p 指向下一个,即 2,然后计算 *p 是 2
所以输出是 2, 1

*p++ 肯定是 *p, 然后 p++ 的
------解决方案--------------------
cout < < *p ; 是operator < <(cout, *p)的便利写法。所以
cout < <*p < < " " < <*p++ < <endl;
这一句,如果用标准的函数调用形式来写的话,应该是下面的:
operator < <(operator < <(operator < <(operator < <(cout, *p), " "), *p++), endl);

对这条语句进行解析,按照C++右序入栈的方式,*p++的时候,入栈的是1,然后p指向2,也就是2比1后入栈,根据栈先入后出的特性,肯定会先输出2,再输出1
------解决方案--------------------
*p和*p++求值顺序按C、C++标准,是不确定的,不要写出这样的代码。
------解决方案--------------------
The order of operand evaluation matters if one subexpression changes the value of an operand used in another subexpression:

// oops! language does not define order of evaluation
if (ia[index++] < ia[index])


The behavior of this expression is undefined. The problem is that the left- and right-hand operands to the < both use the variable index. However, the left-hand operand involves changing the value of that variable. Assuming index is zero, the compiler might evaluate this expression in one of the following two ways:

if (ia[0] < ia[0]) // execution if rhs is evaluated first
if (ia[0] < ia[1]) // execution if lhs is evaluated first


We can guess that the programmer intended that the left operand be evaluated, thereby incrementing index. If so, the comparison would be between ia[0] and ia[1]. The language, however, does not guarantee a left-to-right evaluation order. In fact, an expression like this is undefined. An implementation might evaluate the right-hand operand first, in which case ia[0] is compared to itself. Or the implementation might do something else entirely.


------解决方案--------------------
顺序是不确定的,
cout < <*p < < " " < <*p++ < <endl;

if (ia[index++] < ia[index])
计算结果的原理一样吗?
都是因为顺序是不确定的?

------解决方案--------------------
如果把那个*P++改成*++P,就得到了 2,2的结果,这还是可以说明1楼是正确的