Passing One Dimensional Arrays to Functions
Before we get into passing arrays, let's review the format for using functions.
Now, let's take a closer look at how those arrays are passed. In C++,
arrays are
not
passed by value to functions, they are passed by
reference. Because of this, you do
not
have to use the &
reference character. You simply
pass the base address of an array to a function. To do
this, just supply the name of the array.
For example, suppose you had made the following declarations:
const int size=10;
int ary[size];
Further suppose you wanted to pass this array to a function
called getMax
which expected the array reference as a parameter.
The call to that function would be:
getMax(ary, size);
Notice that only the array name ary
appears
in the parameter list; it is not followed by any subscripts at all.