Passing Arrays To Functions

Passing arrays to functions
Array can be passed as argument to a function. Array name can be used as an argument for the function declaration. While calling function, we require only array name not the array index or array element .i.e. no subscripts or square brackets are required to invoke/ call a function using array.

A program to read a set of numbers from keyboard and to find out the sum of all elements of the given array using function.

Void main ()
Int a [100], I, n, total;
Int sum (int a [], int n);
Cout<<”\n how many numbers?”;
Cout<<”\n enter the elements”;
For (i=0; i<n; i++)
Cin>> a[i];
total=sum (a, n);
Cout<<”\n the sum of the values of array =”<<total;
getch ();
Int sum (int a [], int n)
Int value=0;
For (i=0; i<n; i++)
Value= value + a[i];
return (value);

Related posts:

  1. Arrays In C++ Arrays in C++ Array is a collection of similar type...
  2. C++ Functions C++ Functions A function is meant for performing a specified...
  3. Defining Member Function In C++ Class methods definitions  (Defining the member functions) Member functions can...
  4. Array Of Class Object Array of class objects Array is a collection of similar...
  5. Loops in C++ Loops in C++ Loop is used when we want to...