considering this function
double avg(double v1,double v2,...)
{
double sum=v1+v2;
int counter=2;
double temp;
va_list pargs;
va_start(pargs,v2);
while((temp=va_arg(pargs,double))!=0.0)
{
sum+=temp;
counter++;
}
va_end(pargs);
return sum/counter;
}
This call printf("%lf\n",avg(3.0,4.5,4.5,3.0,0.0)) returns the correct result but if i delete the last parameter 0.0 if prints -321738127312000000000.0000000 but sum and counter have the right values. I kinda don't understand why i have to check that !=0.0 and have the last param 0.0