Array as a Function’s Parameter




In C program we can pass array as like as variable of a function’s parameter. But in here the syntax of formal parameter and actual parameter are difference. Like-

Formal parameter syntax:

return_data_type function_name(data_type array_name[])
{
……………………….
}

Actual parameter syntax:

function_name(array_name);


Hence in formal parameter we need to write array name include bracket with it’s data type and don’t need to declare array size. where in actual parameter should write only array name in parenthesis.

Example:
#include<stdio.h>
#include<conio.h>
void funcx(int get_array[]) /*function definition*/ /* formal parameter*/
{
int n;
for(n=0;n<5;n++)
{
printf("\n %d",get_array[n]);
}
}
int main()
{
int hsn[5]={10,20,30,40,50};
clrscr();
funcx(hsn); /*function calling*//* actual parameter*/
getch();
return 0;
}