Passing whole one dimensional (1D) array to a function in C
Passing whole 1-D array to a function :-
We can pass whole array as an actual argument to a function the corresponding formal arguments should be declared as an array variable of the same type.
Example :-
#include <stdio.h>
void main()
{
Int I,a[6]={1,2,3,4,5,6};
func (a);
printf(“contents of array:”);
for (i=0;i<6;i++)
printf(“%d”,a[i]);
printf(“\n”);
{
func(int val [])
}
int sum=0,I;
for (i=0;i<6;i++)
{
val[i]=val[i]*val[i];
sum+=val[i];
}
printf(“The sum of squares %d”,sum);
output:-
contents of array: 1 2 3 4 5 6
The sum of squares: 91
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment