next up previous contents
Next: 8.3 Declaring Pointer Variables Up: 8 Arrays and Pointers Previous: 8.1 Declaring and Initializing

8.2 Passing Arrays as Arguments

When an array is passed to a function as an argument, the array's pointer is actually passed, rather than the elements of the array. If the function modifies the array values, the array will be modified, since there is only one copy of the array in memory.

In normal C, there are two ways of declaring an array argument: as an array or as a pointer. IC only allows declaring array arguments as arrays.

As an example, the following function takes an index and an array, and returns the array element specified by the index:

    int retrieve_element(int index, int array[])
    {
        return array[index];
    }

Notice the use of the square brackets to declare the argument array as an array of integers.

When passing an array variable to a function, use of the square brackets is not needed:

    {
    int array[10];

    retrieve_element(3, array);
    }



Fred G. Martin
Fri Mar 29 17:44:15 EST 1996