The order of cout messages is not as expected

c++

Solution

This line in you code:

cout<<add(10.0f,20.0f)<<endl<<add(20,50);

will be translated by the compiler into:

operator<<(operator<<(operator<<(cout,add(10.0f,20.0f)),endl),add(20,50));

As the order of evaluation of function parameters is not mandated by the standard, it just happens that `add(20,50)` is evaluated before `operator<<(operator<<(cout,add(10.0f,20.0f)),endl)`.

Problem

I am confused with the output of below code when I execute it. Code: ``` int add(int a, int b) { cout<<"inside int add function"<<endl; return a+b; } float add(float a, float b) { cout<<"inside float add function"<<endl; return a+b; } int main() { cout<<add(10.0f,20.0f)<<endl<<add(20,50); return 0; } ``` output: ``` inside int add function inside float add function 30 70 ``` I dont understand the order of cout messages are getting printed in console. But I expected the output of above program like below ``` inside float add function 30 inside int add function 70 ``` Could someone explain about above behavior.

Original source

Related problems