Passing an array to a function. - C Function

C examples for Function:Function Parameter

Description

Passing an array to a function.

Demo Code

#include <stdio.h>

#define MAX 10/*w  w w . j  a v a2s  .  c  om*/

int array[MAX], count;

int largest(int num_array[], int length){
    int count, biggest = -12000;

    for ( count = 0; count < length; count++)
    {
        if (num_array[count] > biggest)
            biggest = num_array[count];
    }

    return biggest;
}

int main( void )
{
    for (count = 0; count < MAX; count++)
    {
        printf("Enter an integer value: ");
        scanf("%d", &array[count]);
    }
    printf("\n\nLargest value = %d\n", largest(array, MAX));

    return 0;
}

Related Tutorials