Using references with functions
So far, we have minimally demonstrated references by using them to establish an alias for an existing variable. Instead, let’s put forth a meaningful use of references, such as when they are used in function calls. We know most functions in C++ will take arguments, and we have seen many examples in the previous chapters illustrating function prototypes and function definitions. Now, let’s augment our understanding of functions by passing references as arguments to functions, and using references as return values from functions.
Passing references as arguments to functions
References may be used as arguments to functions to achieve call-by-reference, rather than call-by-value, parameter passing. References can alleviate the need for pointer notation in the scope of the function in question as well as in the call to that function. Object or .
(member selection) notation is used to access struct
or class
members for formal parameters...