Reputation: 1854
I have the following functions:
int sum(int *a, int size) {
int sum;
int i;
for(i = 0; i < size; i++) {
sum += a[i];
}
return sum; /* Change the return value */
}
and
double average(int *a, int size) {
int summation = sum(*a, size);
double result = (double) summation/size;
return result; /* Change the return value */
}
and when I compile, I get the error: passing argument makes pointer from integer without a cast
What should I change?
Upvotes: 0
Views: 1383
Reputation: 161
Since a is an array, just passing a will give the base address of the array, so just pass a in the argument.
Upvotes: 0
Reputation: 15501
In your average
function, don't pass *a
to sum
, but just a
since it's already a pointer.
Upvotes: 1