C语言函数参数不定的例程

来源:互联网 发布:fedora安装wine软件 编辑:程序博客网 时间:2024/06/04 18:28
#include <stdio.h>#include <stdrag.h>void display(int,int, ...);void main(){  display(1,2,5,6);  display(2,4,'A','a','b','c');  display(3,3,2.5,299.3,-1.0);}void display(int type,int num, ...){  int i,j;  char c;  float f;  va_list ptr;  va_start(ptr,num);  printf("\n");  switch(type)  {    case 1:      for( j = 1; j<= num; j++ )      {        i = va_arg(ptr,int);        printf("%d ",i);      }      break;    case 2:      for( j = 1; j <= num; j++ )      {        c = va_arg(ptr,char);        printf("%c ",c);      }      break;    case 3:      for( j = 1; j <= num; j++ )      {        f = (float)va_arg(ptr,double);        printf("%f ",f);      }  }}

原创粉丝点击