C++’s std::cout seems to be an interesting thing. I tried the following program on my C++ compiler today:
cout<<"!"<<"@"<<endl;
cout<<"!"<<cout<<"@"<<endl;
cout<<"!"<<(cout<<"@")<<endl;
And the outputs are rather curious:
!@
!0x601068@
@!0x601068
The first line is pedestrian; the second is understandable; however, the third line is beyond my knowledge. Could someone explain the output? Thank you guys all in advance!
Ziyao Wei
This line:
It is first executing:
Note: It could have executed something else first, but the compiler optimized this sub-expression and found it could move this to the start of the statement without breaking any constraints.
The result of this expression is a stream (cout). So the resulting expression is:
This results in: