Electrical and Computer Engineering
9
of 17
UAH
CPE 112
Passing Arrays as Arguments
•
By default, C++ simple variables are always
passed by value.
•
Arrays are always passed by reference.
–
Example:
–
•
void
ZeroOut (
/* out */
float
arr[],
•
/* in */
int
numElements)
•
{
–
int
i;
–
for
(i = 0; i < numElements; i++)
»
arr[i] = 0.0
•
}
»