The deviation function throws me the following error: "Array subscript is not an integer". If you can help me locate the cause of error I'll appreciate it.
float average(float data[], int n) {
float total = 0;
float *p = data;
while (p < (data + n)) {
total = total + *p;
p++;
}
return total / n;
}
float deviation(float data[], int n) {
float data_average = average(data, n);
float total;
float *p = data;
while (p < (data + n)) {
total += (data[p] - data_average) * (data[p + 1] - data_average);
}
return total / 2;
}
datos[p],pis a pointer, not an integer. You can't do that. (Well, you can do silly things like5[array], but you're not doing that here;datosis also a pointer.)array[5]is equivalent to*(array + 5)and same for5[arraywhich is equal to*(5 + array). That's whyarray[5] = 5[array]. where/why would one use something like that?: I think it is used only for obfuscation :)x[y]is by definition equivalent to*(x+y), and addition is commutative (even for pointer+integer). See this question; the accepted answer is massively upvoted, but my answer goes into the history.