The order of cout messages is not as expected

前端 未结 2 886
闹比i
闹比i 2021-01-13 06:52

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\"<

        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 07:08

    This line in you code:

    cout<

    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).

提交回复
热议问题