/* va_arg example */
#include <stdio.h> /* printf */
#include <stdarg.h> /* va_list, va_start, va_arg, va_end */
#include <stdlib.h>
int getTheLargest(va_list vl, int n, int* pVarray)
{
int val;
int largest =0;
for (int i=0;i<n;i++)
{
val=va_arg(vl,int);
largest=(largest>val)?largest:val;
pVarray[i] = val;
}
va_end(vl);
return largest;
}
int findMax (char a, int n, ...)
{
int* pVarray = (int*)malloc(sizeof(int)*n);
va_list vl;
va_start(vl,n);
return getTheLargest(vl, n, pVarray);
}
int main()
{
printf ("The largest value is: %d\n",
FindMax (‘a‘, 2, 702,822,631,834,892,104,772));
system("PAUSE");
}