Tuesday, 6 August 2013

Reverse order when using std::cout [duplicate]

Reverse order when using std::cout [duplicate]

This question already has an answer here:
Parameter evaluation order before a function calling in C 13 answers
cout << order of call to functions it prints? 2 answers
The program below outputs 10. I expected it to first print 0 (the else
branch of function f) and then to print 1. How come that the order is
reversed?
#include <iostream>
using namespace std;
int f(bool& b){
if (b==true){
return 1;
} else {
b=true;
return 0;
}
}
int main () {
bool b=false;
cout<<unitbuf<<f(b)<<unitbuf<<f(b);
return 0;
}
The output
10

No comments:

Post a Comment