< previous page page_610 next page >

Page 610
        destination[i] = source[i];
}
The word const guarantees that any attempt to modify the source array within the Copy function results in a compile-time error.
Here's a table that summarizes parameter passage for simple variables and one-dimensional arrays:
ParameterFormal Parameter
Declaration
for Pass-by-Value
Formal Parameter
Declaration
for Pass-by-Reference
Simple variableint costint& price
ArrayImpossible*int arr[]
*However, prefixing the array declaration with the word const prevents the function from modifying the parameter.

One final remark about parameter passage: It is a common mistake to pass an array element to a function when passing the entire array was intended. For example, our ZeroOut function expects the base address of a float array to be sent as the first parameter. In the following code fragment, the function call is an error.
float velocity[30];
  .
  .
  .
ZeroOut(velocity[30], 30);    // No
First of all, velocity[30] denotes a single array element-one floating point number-and not an entire array. Worse yet, there is no array element with an index of 30. The indices for the velocity array run from 0 through 29.
Processing Arrays
Three types of array processing occur especially often: using part of the declared array (a subarray), using two or more arrays in parallel (parallel arrays), and using index values that have specific meaning within the problem (indices with semantic content). We describe each of these methods briefly here, and leave further examples to the case studies at the end of the chapter.

 
< previous page page_610 next page >