Return values for C + + functions

Source: Internet
Author: User

return value:

1. The return value of the main () function: The main function main return value can be treated as a status indication, returning 0-bit success

2. Return non-reference type:

(1) The return value of the function is used to initialize the temporary object created when the function is called, and if the return type is not a reference, the return value of the function is copied to the temporary object where the function is called.

(2) When solving an expression, if a place is needed to store its results, the compiler creates an unnamed object.

(3) Initializing the temporary object with the function return value is the same as the initial taxiing parameter with the argument.

(4) When the return value is a non-reference type, the return value can be a local object, or it can be the result of solving an expression.

3. Return the reference type:

(1) When the function returns a reference type, the return value is not copied, instead, the object itself is returned.

(2) Never return a reference to a local object, or never return a pointer to a local object!

(3) When a reference is returned, it is required that in the parameters of the function, there are parameters that exist in the form of a reference or pointer, which need to be returned .

4. Const type:

(1) The return value cannot be modified

Return values for C + + functions

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.