Since arrays are always passed by reference, all changes made to the array elements inside the function will be made to the original array.
int ProcessValues (int [], int ); // works with ANY 1-d array
Example:
#includeusing namespace std;int SumValues (int [], int ); //function prototypevoid main( ){ int Array[10]={ 0,1,2,3,4,5,6,7,8,9}; int total_sum; total_sum = SumValues (Array, 10); //function call cout <<”Total sum is “ <
The only way to protect the elements of the array from being inadvertently changed, is to declare an array to be a const parameter.
#includeusing namespace std;int SumValues (const int [], int); //function prototypeint main( ){ const int length =10; int Array[10]={ 0,1,2,3,4,5,6,7,8,9}; int total_sum; total_sum = SumValues (Array, length); //function call cout <<”Total sum is “ <
Reference:
http://stackoverflow.com/questions/23035407/passing-1d-and-2d-arrays-by-reference-in-c
http://doursat.free.fr/docs/CS135_S06/CS135_S06_8_1D_Arrays2.pdf