va_start - C stdarg.h

C examples for stdarg.h:va_start

type

macro

from

<cstdarg>

Description

Initialize a variable argument list

Prototype

void va_start (va_list ap, paramN);

Return Value

none

Demo Code


#include <stdio.h>
#include <stdarg.h>

int FindMax (int n, ...){
  int val,largest;
  
  va_list vl;/*  w  ww.  j av  a  2s  .  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