We can create functions that receive an array as an argument. To pass an array into a function, we need to write the name of the array in the function call. We have to pass the size of an array as a parameter. Size may or may not be required.

Exclusion of size can be done in ‘\0’ terminated character arrays, and size can be determined by checking the end of the string character. You can pass both one dimensional and multi-dimensional arrays into the function.

A single array element or an entire array itself can be passed into the function. This passing of an array can be done for both one dimensional as well as a multi-dimensional array.

Syntax:

function_name (array_name);

Passing one dimensional array:

  • Passing individual array elements to a function is almost identical to passing variables to a function.

Eg:

#include <stdio.h>

void display (int height1, int height2)

{

printf (“ %d \n” , height1);

printf (“ %d \n” , height2);

}

int main()

{

int heightArray[] = {162, 168, 164, 165};

//passing index numbers to the get the output

display (height1[2], height2[3]);

return 0;

}