<<
is a function, namely something like ostream& operator<<(ostream& lhs, RhsType rhs)
.
cout << a;
is equivalent to
operator<<(cout, a);
The function returns lhs, that is return lhs
, - so in the above examples cout
is returned.
So your example
cout << i << ++i << i++ ;
is equivalent to
operator<<(operator<<(operator<<(cout, i), ++i), i++);
Correction C++ does not specify which order the increment operations are performed. It seems logical to you and me that the most nested would go first, but as far as the compiler is concerned it is free to execute the increment whenever it likes. It is the same behaviour as a function like myFunc(cout, i++, ++i, i)
where the order in which the increments are evaluated is undefined. The only thing guaranteed is the functions are evaluated inside to outside.