va_arg - C stdarg.h

C examples for stdarg.h:va_arg

Type

macro

From

<cstdarg>

Description

Retrieve next argument

Prototype

type va_arg (va_list ap, type)

Return Value

Returns the current additional argument as an expression of type type.

Demo Code


#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;
} 

Related Tutorials