There i something i dont get, if have the following:
double average (double scores[]){
double sum = 0;
int n;
int nscores = sizeof(scores)/sizeof(double);
for (n=0 ;n<nscores ;++n){
sum+=scores [n];
return sum/nscores;
}
and i send this function an array like this:
double scores[3]={1,2,3};
why will sizeof(scores) will be 0?
sizeof(scores), inside the function, is equivalent tosizeof(double *): the compiler has no way to tell, at that point, how big the array was.It won’t be zero, but because
sizeof(scores)andsizeof(double)are both integer-type expressions,sizeof(scores)/sizeof(double)is integer division, so ifsizeof(scores) < sizeof(double), thensizeof(scores)/sizeof(double) == 0.