9.4 Summary of Parameter Types

I l @ ve RuBoard

Table 9-2 lists the various parameter types.

Table 9-2. Parameter types

Type

Declaration

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.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net