Since arrays is always passed by reference, all changes made to the array elements inside the function would be made to th E original Array.
int processvalues (int [], int); Works with any 1-d array
Example:
#include <iostream>using namespacestd;intSumvalues (int[],int);//function prototypevoidMain () {intarray[Ten]={0,1,2,3,4,5,6,7,8,9}; inttotal_sum; Total_sum= Sumvalues (Array,Ten);//function Callcout << "Total sum is"<<total_sum;}intSumvalues (intValues[],intNum_of_values)//function Header{ intsum =0; for(intI=0; i < num_of_values; i++) Sum+=Values[i]; returnsum;}
The only-to-protect the elements of the array from being inadvertently changed, are to declare an array to be a const p Arameter.
#include <iostream>using namespacestd;intSumvalues (Const int[],int);//function prototypeintMain () {Const intLength =Ten; intarray[Ten]={0,1,2,3,4,5,6,7,8,9}; inttotal_sum; Total_sum= Sumvalues (Array, length);//function Callcout << "Total sum is"<<total_sum; return 0;}intSumvalues (Const intValues[],intNum_of_values)//function Header{ intsum =0; for(intI=0; i < num_of_values; i++) Sum+=Values[i]; returnsum;}
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
Passing in a one-dimensional array to a function passing 1D array to function