C examples for stdarg.h:va_arg
macro
<cstdarg>
Retrieve next argument
type va_arg (va_list ap, type)
Returns the current additional argument as an expression of type type.
#include <stdio.h> #include <stdarg.h> int FindMax (int n, ...){ int val,largest; va_list vl;/* w ww . j a va 2 s . c o m*/ va_start(vl,n); largest=va_arg(vl,int); for (int i=1;i<n;i++){ val = va_arg(vl, int); largest=( largest > val ) ? largest : val; } va_end(vl); return largest; } int main (){ int m; m= FindMax (17,7,4,61,84,2,10,72); printf ("The largest value is: %d\n",m); return 0; }