// initializes an array using a function // Sean McCulloch // Date: 6/25/97 #include using std::cout; using std::endl; using std::cin; void initialize(int [], int, int); // initializes an array int main(){ const int size=20; // size of the array int test[size]; // array to manipulate int initVal; // value to assign to array cout << "what do you want to assign to array? "; cin >> initVal; initialize(test, size, initVal); // initialize it // what happens if we call this function? // initialize (test, size+10, 1); // print out the array for(int i=0; i < size; ++i) cout << "test[" << i << "]=" << test[i] << endl; } // assign every element of the array A the value val // treat n to be the size for the array void initialize(int a[], int n, int val){ // why can't we use "size" here directly instead of passing // it as a parameter? for(int i=0; i < n; ++i) a[i] = val; }