Talk:C++ Programming/Programming Languages/C++/Code/Statements/Variables/Operators

"Chaining

std::cout << "The sum of " << a << " and " << b << " is " << sum << "\n"; ... successively the expressions std::cout << " and ", std::cout << b, std::cout << " is ", std::cout << " sum ", std::cout << "\n" are evaluated and the whole series of chained values is printed."

83.26.176.231 (discuss) 12:54, 22 August 2011 (UTC) This part of book suggest that "cout<<" compute from left to right. But let's look at this program:

[code]
 * 1) include

using namespace std;

class matematyka {   private: int a, b, c;

public: matematyka {       a=1; b=2; c=3; }   int ab{a=a+b; return a;} int ac{a=a*c; return a;} int aa{return a;} int bb{return b;} int cc{return c;} }a;

int main {

cout << a.aa << " " << a.bb << " " << a.cc << " " << a.ac << " " << a.ab << " " << a.aa << " " << a.bb << " " << a.cc << endl;

return 0; }

[/code]

if we run this program we will see: 9 2 3 9 3 1 2 3 which shows that "cout<<" calculet from right to left (a.cc=3, a.bb=2, a.aa=1, a.ab=1+2=3=a, a.ac=3*3=9=a, a.cc=3, a.bb=2, a.aa=9 ) and then put it on the screen in right order.

(example compiled with code::blocks on ubuntu 11.04)


 * The order of the function calls is undefined. I will try to provide some information to that fact. You can also contribute to the book, research a bit, structure the concepts and attempt to put it in a way you would like to have read it in the first place. --Panic (discuss • contribs) 18:23, 22 August 2011 (UTC)