Explain Please what these lines mean.
Better still would be to take an initial guess to help others help you by at least having a frame of reference.
But...
#include <iostream>
using namespace std;
int sum(int[],int);// (1) function declaration or prototype
int main()
{
int a[]={11,33,55,77};// (2) initialization of an array
int size=sizeof (a)/sizeof(int);// (3) initialize size with number of elements in a
cout << "sum(a,size)="<<sum(a,size)<<endl;
}
int sum(int a[],int n)// (4) function definition
{
int sum=0;
for ( int i=0;i<n;i++ )
sum+=a[i];
int Avg= sum/4;
cout<<"Avg="<<Avg<<endl;
return sum;
} More details:
- This says, this function will exist and this is how it should be used.
- The size of the array is left to the compiler to figure out based on the number of elements initializing it.
- The number of elements in an array is equal to the total size divided by the size of the first member.
- The definition of the function: "the meat".
Last edited by Dave Sinkula; Aug 9th, 2006 at 12:31 am.
Reputation Points: 2780
Solved Threads: 312
long time no c
Offline 4,790 posts
since Apr 2004