/*******************************/
//va_start、va_end、va_arg 实现可变长参数
/*******************************/
#include <stdarg.h>
#include <stdio.h>
#define END_NUM -1
void trease_array(int first_num,...)
{
int result1 = 0;
int result2 = 0;
int temp = 0;
va_list ap;
va_start(ap,first_num);
result1 =first_num;
while( (temp = va_arg(ap,int)) != END_NUM)
{
result1 += temp;
}
printf("%d\n",result1);
va_end(ap);
}
int main(void)
{
trease_array(1,2,3,4,5,END_NUM);
return 0;
}
原文地址:https://www.cnblogs.com/muzixiaofeng/p/10088734.html
时间: 2024-11-10 11:41:37