Passing Array to function
Passing Array to function
With the help of Pointer we can pass Array as a argument in Function. Array name is a also a pointer variable that hold the address of zero index number element, so when we pass a array name, then we passing the address of zero index number so we need a pointer variable to hold the address of zero index number.
The Syntax of declaring a function:
Return type function_name(data_type pointer_variable_name,…..);
Example:
Void printIntArray(int *,int);
#include<stdio.h>
void printArray(int *,int);
int main()
{
int numbers[5]={7,8,3,6,7};
printArray(numbers,5);
return 0;
}
void printArray(int *ptr,int l)
{
int i;
printf("\nArray elements Are: ");
for(i=1;i<=l;i++)
{
printf("\t%d",*ptr);
ptr++;
}
}