可变参数处理,stdarg.h

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

int print_ags(int begin,...)
{
	va_list ap;
	char* p;
	int n;
	va_start(ap,begin);
	p = va_arg(ap,char*);
	n = 0;
	while(p != NULL)
	{
		n++;
		printf("arg %d: %s\n",n,p);
		p = va_arg(ap,char*);
	}
	va_end(ap);
	return n;
}

int main(vaoid)
{
	int n;
	n = print_ags(-1,"hello","world",NULL);
	printf("first, without NULL : %d\n",n);

	n = print_ags(-1,"China","beijing","Olympic",NULL);
	printf("second, without NULL : %d\n",n);
	return 0;
}

你可能感兴趣的:(可变参数处理,stdarg.h)