/* Example: how to add the corresponding values from two arrays of the same size. */ #include /* Declare the function that adds the two arrays a1 and a2. It can compute the array result[] because it gets address of the 0-th element result[0] as one of its argument. Therefore, it can modify any elements in result[]. The type of this function is void because it returns all its work implicitly by computing elements of result[]. The declaration "const" indicates that the array must not be modified by the function. */ void addArrays (const int a1[], const int a2[], int result[], int n); int main (void) { int x[] = {1,2,3,4}, i; int y[] = {10,20,30,40}; int z[4]; /* Call the function with names of the arrays as factual arguments. Recall that the name of an array is the address of the 0-th element in the array. In other words, we pass to this function addresses of 0-th elements of 3 arrays. Therefore, the function can modify any of the arguments unless an array is declared to be constant. */ addArrays (x, y, z, 4); /* print a report */ for (i=0; i<4; ++i) printf ("%3d", x[i]); printf ("\n + \n"); for (i=0; i<4; ++i) printf ("%3d", y[i]); printf ("\n-------------\n"); for (i=0; i<4; ++i) printf ("%3d", z[i]); printf ("\n"); return (0); } void addArrays (const int a1[], const int a2[], int result[], int n) { int i; /* do the adding of every corresponding cells */ for (i=0; i