- Arrays are automatically passed to functions as reference parameters (no ampersand is necessary); it is incorrect to include an ampersand in the function header
- It is not possible to pass an array by value; you can pass a single element by value, but not an entire array
- This means that in all of the previous examples that passed arrays to functions, the arrays were output parameters; the changes made to the array elements were visible to the caller
- To safeguard an array so the caller cannot change any values, use the const modifier in the function header (declaration and definition)
This is a better declaration for a function that will add two arrays together:
void addArrays(const int firstArray[],
const int secondArray[],
int resultArray[],
int sizeOfArray);
Notice the const keyword. It tells the compiler that any attempt to modify the array elements within the addArrays(...) function should be prohibited.