When an entire array is passed to a function, the base address of the array is
passed instead of individual elements. As a result, the function gains access to
all elements of the array.

Since arrays are passed by reference, any changes made to array elements inside
the function are reflected in the calling function. To correctly process an
array, the function is usually provided with the array size as an additional
parameter.
SYNTAX:

return_type function_name(datatype array_name[], int size);
EXAMPLE:

#include <stdio.h>


void printAll(int arr[], int size) {
    for(int i = 0; i < size; i++) {
        printf("Array element %d: %d\n", i, arr[i]);
    }
}

int main() {
    int tinWeight[3] = {10, 20, 30};

    
    printAll(tinWeight, 3);

    return 0;
}
Previous Next