Using pointers with functions
Functions in C++ will undoubtedly take arguments. 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 pointers as arguments to functions, and using pointers as return values from a function.
Passing pointers as arguments to functions
Arguments passed from actual to formal parameters in a function call are by default copied on the stack. In order to modify the contents of a variable as an argument to a function, a pointer to that argument must instead be used as a function parameter.
Any time an actual parameter is passed to a function in C++, a copy of something is made and passed on the stack to that function. For example, if an integer is passed as an actual parameter to a function, a copy of that integer is made and then passed on the stack to the function to be received as the formal parameter. Changing the formal...