The result of int c=0; cout<<c++<<c;

后端 未结 5 1906
无人及你
无人及你 2020-12-06 19:29

I think it should be 01 but someone says its \"undefined\", any reason for that?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 20:20

    The reason it is undefined is that the compiler is free to calculate function parameters in any order. Consider if you where calling a function (because you are, but it's easier to envision when it's in function syntax):

    
      cout.output(c++).output(c);
    

    The compiler may hit the parameters in reverse order, forward order, or whatever. It may call the first output before calculating the parameter to the second output or it may do both and then call.

提交回复
热议问题