C + + cout execution order

Source: Internet
Author: User

C + + cout execution order

The problem description is this: If the function is called in cout , and the function contains an output statement, which sentence will be output first?

A closer look, suddenly found that the content of C + + forgotten, and did not see the output of the succession problem.

The implementation is as follows:

1 intMaxintXinty)2 3 {4 5 intmax=0;6 7max= (x>y)?x:y;8 9cout<<"2. max="<<max<<Endl;Ten  One returnMax; A  - } -  the intMainintargcChar*argv[]) -  - { -  +cout<<"1. max="<<max (6,8) <<Endl; -  + return 0; A  at}

Execution results

After querying the data, it is concluded that the cout is bound to the left, that is, the cout is executed from the back , and the order of the parameters stack is from right to left. This Endl will be called First, then Max (6,8) and "1. Max= "

, in fact, this problem is not very difficult, but the point to note is the combination of direction. If we think from the perspective of implementation, we can also get the same answer, combining the memory model of C + + and the features of C + + to let us keep this in mind.

Record it and leave it for later, while being convenient for others.

Can contact me for communication. [email protected]

Thank you for your support.

2016.3.25

:

C + + cout execution order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.