Table 9-2. Parameter types
Call by value
|
function(int var)
Value is passed into the function and can be changed inside the
function, but the changes are not passed to the caller.
|
Constant call by value
|
function(const int var)
Value is passed into the function and cannot be changed.
|
Reference
|
function(int& var)
Reference is passed to the function. Any changes made to the
parameter are reflected in the caller.
|
Constant reference
|
function(const int& var)
Value cannot be changed in the function. This form of parameter is
more efficient than "constant call by
value" for complex data types. (See Chapter 12.)
|
Array
|
function(int array[])
Value is passed in and may be modified. C++ automatically turns
arrays into reference parameters.
|
Call by address
|
function(int *var)
Passes a pointer to an item. Pointers are covered in Chapter 15.
|