What are the characteristics of "reference" as a function parameter

Source: Internet
Author: User

(1) The effect of passing a reference to a function is the same as passing a pointer . At this point, the parameter of the function is used as the real parametric or an alias of the object in the original central melody function, so the operation of the parameter variable in the function is the operation of its corresponding target object (in the central Melody function).

(2) using the parameters of the reference transfer function, in memory does not produce a copy of the argument, it is directly to the actual parameter operation , and the use of the general variable transfer function parameters, when a function call, you need to assign a storage unit to the parameter, the parameter variable is a copy of the argument variable; The copy constructor is also called. Therefore, when the parameter passes the data is large, uses the reference to pass the parameter with the general variable efficiency and occupies the space to be good.

(3) The use of pointers as parameters of the function, although can also achieve with the effect of reference, but in the function of the parameter is also assigned to the parameter storage unit , and need to reuse the "* pointer variable name" in the form of operations, which is prone to errors and poor program reading; On the other hand, at the call point of the keynote function, you must use the address of the variable as an argument. And references are easier to use and clearer.

What are the characteristics of "reference" as a function parameter

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.