代码
#include <stdio.h>

//重要引用
#include <stdarg.h>

void sum(char* msg,...);
int main(int argc, char* argv[])
{
        sum(
"The total of 1+2+3+4 is %d\n",1,2,3,4,0);//最后的0作为sum函数循环跳出标识
        return 0;
}

void sum(char* msg,...)
{
        
int total=0;
        va_list ap;
        
int arg;
        va_start(ap,msg);
        
while((arg=va_arg(ap,int))!=0)//0跳出标识
        {//循环获得参数值
                total+=arg;
        }
        printf(msg,total);
        va_end(ap);
}

 

相关文章:

  • 2021-08-11
  • 2021-12-01
  • 2021-05-23
  • 2021-12-06
  • 2021-06-04
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
相关资源
相似解决方案