Explain Passing arrays to a function with example

Explain Passing arrays to a function



One dimensional arrays :
To pass a one-dimensional array to a called function, it is sufficient to list the name of the array, without any subscripts and the size of the array as arguments.
For example :
Declaration : void largest(int [ ],int);
Calling        : largest(a,n)
Definition    : void largest(int a[ ],int n)
                      {


                        }

Three rules to pass an array to a funcion

1. The function must be called by passing only the name of the array.
      for example : largest(a);
2. In the function definition, the formal parameter must be an array type, the size of the array does not need to be specified.
     for example : void largest(int a[ ])
                           {


                           }
3. The function prototype must show that the argument is an array.
     for example : void largest(int [ ]);
 

Labels: