Mat.S
Mat.S

Reputation: 1854

Passing argument 1 of 'sum' makes pointer from integer without a cast

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

Answers (2)

kharevbv
kharevbv

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

ooga
ooga

Reputation: 15501

In your average function, don't pass *a to sum, but just a since it's already a pointer.

Upvotes: 1

Related Questions