There are three kinds of methods for transmitting parameters in C + +: Value passing (copy), pointer passing (address), reference passing (alias).
(1) Value passing: In fact, an assignment operation, when an argument is passed to a formal parameter, an additional copy is generated, and the parameter is just a copy of the argument, so the operation of the parameter within the function is not updated to the source argument. At the end of the function, the parameter is freed as a local variable and has no effect on the argument. If the object of the class invokes the copy construct, this deep copy operation will affect the efficiency of the transfer parameter.
(2) pointer passing: Because the address of the actual argument is passed, the pointer points to the same object in memory, so the inside of the function will "update" the parameter to the argument synchronously.
(3) Reference passing (c + + specific): The alias of an argument is passed, and when the parameter is bound to an argument object, the operation of the parameter inside the function is also "synchronously updated" to the source argument.
Note: For pointer passing and reference passing, parameter changes are a side effect of changing arguments, and we can easily modify the passed arguments by using this side effect, in addition, this avoids the copy in the value passing, and can effectively improve the efficiency for the argument of big data. Therefore, for situations where you want to increase the efficiency of the communication and do not want to affect the arguments, you can use the const:
C + + Three kinds of method of transmitting parameters