Passing Arrays to Functions
- Arrays are passed by pointer.
- This is very close to pass by reference but not exactly the same.
- Remember, a pass by value means copy everything.
- And this can be VERY expensive for large arrays.
- So in C, you were not permitted to pass arrays by value.
- Passing arrays by reference is not permitted either.
- In C++ you can pass
const
arrays
- Array Parameters.
- The optional reserved work
const
- An array parameter is the type, an identifier and square brackets.
- The size inside the square brackets is optional.
- For higher dimension arrays, it is required for all but the first dimension
-
void PrintArray(int ary[]);
-
void PrintArray(int ary[MAX_SIZE]);
-
void PrintArray(const int ary[MAX_SIZE]);
-
void PrintArray(const int ary[]);