// John Bent's CS 110 Hand-out 9 // Passing arrays // // This program does nothing more than demonstrate // the syntax of passing an array to a function. #include // function prototypes void fillIt ( int[] ); // one way void showIt ( int*, int ); // another const int SIZE = 5; void main() { int array1[SIZE]; fillIt(array1); // show the thing, did it work showIt(array1, SIZE); } // this method includes the size in the brackets of the array. // void fillIt (int localArray[SIZE]) { for (int i = 0; i < SIZE; i++) { localArray[i] = 3; } } // this method passes the size as a seperate argument, this method // is more flexible. Usually a function will not know the size of // the array it is being passed. // void showIt (int localArray[], int size) { for (int i = 0; i < size; i++) cout << localArray[i] << " "; }