(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