va arg

Solutions on MaxInterview for va arg by the best coders in the world

showing results for - "va arg"
Martina
26 Feb 2018
1/* va_arg example */
2#include <stdio.h>      /* printf */
3#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */
4
5int FindMax (int n, ...)
6{
7  int i,val,largest;
8  va_list vl;
9  va_start(vl,n);
10  largest=va_arg(vl,int);
11  for (i=1;i<n;i++)
12  {
13    val=va_arg(vl,int);
14    largest=(largest>val)?largest:val;
15  }
16  va_end(vl);
17  return largest;
18}
19
20int main ()
21{
22  int m;
23  m= FindMax (7,702,422,631,834,892,104,772);
24  printf ("The largest value is: %d\n",m);
25  return 0;
26}
27
28
29// Output:
30// The largest value is: 892