Passing whole one dimensional (1D) array to a function in C

No comments


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

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀