C中函数传入参数不确定问题

va_list: This type is used as a parameter for the macros defined incstdarg to retrieve the additional arguments of a function.

Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for theva_start, va_arg and va_end macros.

va_start is in charge of initializing an object of this type, so that subsequent calls tova_arg with it retrieve the additional arguments passed to the function.

Before a function that has initialized a va_list object with va_start returns, theva_end shall be executed.

 

example:

/* va_arg example */
#include <stdio.h>
#include <stdarg.h>

int FindMax ( int amount, ...)
{
  int i,val,greater;
  va_list vl;
  va_start(vl,amount);
  greater=va_arg(vl,int);
  for (i=1;i<amount;i++)
  {
    val=va_arg(vl,int);
    greater=(greater>val)?greater:val;
  }
  va_end(vl);
  return greater;
}

int main ()
{
  int m;
  m= FindMax (7,702,422,631,834,892,104,772);
  printf ("The greatest one is: %d\n",m);
  return 0;
}


 

 



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值