Two reasons to use a reference:
1. The programmer can modify the data object in the calling function.
2, by passing the reference without passing the entire data object, you can improve the speed of the program.
For functions that use passed values without modification:
If the data object is small, you can pass the value directly.
If the data object is an array, use the pointer, because this is the only choice, and the pointer is declared to be a const-only pointer.
If the data object is a large structure, use a const pointer or a const reference to improve program efficiency. This saves time and space needed to replicate the structure.
If the data object is a class object, a const reference is used. The semantics of class design often require the use of references.
For functions that modify the data in the calling function:
If the data object is a built-in data type, the pointer is used.
If the data object is an array, you can only use pointers.
If the data object is a struct, the reference or pointer is used.
If the data object is a class object, the reference is used.
This article is from the "Boundless" blog, please make sure to keep this source http://7492110.blog.51cto.com/7482110/1599191
C + + references and pointers