Performing Operations on Entire Arrays

Assume you have arrays, a, b, and c:
int a[10], b[10], c[10];
You cannot do any of these operations:
1. a = b        // can't assign one to another
2. if (a == b)  // can't compare
3. c = a + b    // can't add, sub, mult, divide 
4. cout << a    // can't output entire array
5. return a     // can't return an array
You must perform the operation on each element individually. For example, array assignment:
for (int i = 0; i < 10; i++)
  a[i] = b[i];
If you had a function that could sort an array of integers, you could pass an entire array by passing the name of the array:
sortArray(a);  // the entire array is passed in
Previous page
Next page

Back to Lesson 11 Index
Back to Outline