c语言有关指针与函数的问题

average函数的功能是计算成绩数组中的平均成绩,并将平均成绩返回。


```c
#include 

double average (int n, int *score) {
    double sum=0;
    for(;score-1;score++) sum+=*score;
    return sum/n;
}

int main () {
    int n = 10, score[10] = {88, 99, 76, 78, 89, 93, 95, 86, 92, 85};
    double ave_score;
    ave_score = average(n, score);
    printf("%f\n", ave_score);
    return 0;
}

```

average的 累加换成如下:

double average (int n, int *score) {
    double sum=0;
    //for(;score<score+n-1;score++) sum+=*score;
    for (int i = 0; i < n; i++)
        sum += *(score + i);
    return sum/n;
}