#include <stdio.h>
#include <stdarg.h>
double AddDouble(int x,...);
// this is not a code written by me
// this is an example of from Sams teach yourself C in 24
// written by Tony Zhang
main(){
double d1=1.5;
double d2=2.5;
double d3=3.5;
printf("Given an argument: %2.1f\n",d1);
printf("The result returned by AddDouble() is: %2.1f\n n",AddDouble (1, d1));
printf("Given an argument: %2.1f and %2.1f \n",d1, d2);
printf("The result returned by AddDouble() is: %2.1f\n n",AddDouble (1, d1, d2));
printf("Given an argument: %2.1f, %2.1f , and %2.1f \n",d1, d2, d3);
printf("The result returned by AddDouble() is: %2.1f\n n",AddDouble (1, d1, d2, d3));
}
double AddDouble(int x,...)
{
va_list arglist;
int i;
double result=0.0;
printf("the number of arguments is:%d\n", x);
va_start (arglist, x);
for (i=0; i<x; i++)
result += va_arg ( arglist, double);
va_end (arglist);
return result;
}
/*
well understand how to do functions but it's just this header file with this function I do not understand it. I know that the AddDouble function is called upon by the printe function, but I really don't know what the arguments mean. Also the for loop I do not understand it, there's also the result why is it initialized with 0 and "i" is not initialized before the loop, so please I need help, thank you.Can someone be kind enough as to explain to me how this works?*/



LinkBack URL
About LinkBacks
Can someone be kind enough as to explain to me how this works?*/ 



