Declaration:
void va_end(va_list ap);
Allows a function with variable arguments which used the
va_start macro to return. If va_end
is not called before returning from the function, the result is
undefined. The variable argument list ap may no longer be
used after a call to va_end without a call
to va_start .
Example:
#include<stdarg.h>
#include<stdio.h>
void sum(char *, int, ...);
int main(void)
{
sum("The sum of 10+15+13 is %d.\n",3,10,15,13);
return 0;
}
void sum(char *string, int num_args, ...)
{
int sum=0;
va_list ap;
int loop;
va_start(ap,num_args);
for(loop=0;loop<num_args;loop++)
sum+=va_arg(ap,int);
printf(string,sum);
va_end(ap);
}
|