is it possible to do this?
void putAverage(float *avg, int *arrData, int size) {
int i,sum = 0;
for(i = 0;i < size;i++) {
sum += *(arrData + i);
}
*avg = sum / size;
}
int main() {
float i;
putAverage(&i, {1, 2, 3, 4, 5}, 5);
printf("%f\n",i);
}
because if i run it, it shows error like this
error: expected expression before '{' token
error: too few arguments to function 'putAverage'
note: declared here
if it possible please make a correction, if not please give me the best way to do it.
{1, 2, 3, 4, 5}-->(int[]){1, 2, 3, 4, 5},*avg = sum / size;-->*avg = (float)sum / size;arrData[i]than*(arrData + i)– and there's no performance difference.