Ellipsis ('...') Operator

The ellipsis ('...') consists of three successive periods with no whitespace intervening. An ellipsis can be used in the formal argument lists of function prototypes to indicate a variable number of arguments, or arguments with varying types. For example:

void func (int n, char ch, ...);
This declaration indicates that func will be defined in such a way that calls must have at least two arguments, int and char, but can also have any number of additional arguments.

Example:

#include <stdarg.h>


int addvararg(char a1,...){
va_list ap;
char temp;
va_start(ap,a1);

while( temp = va_arg(ap,char))
  a1 += temp;
return a1;
}


int res;
void main() {


  res = addvararg(1,2,3,4,5,0);
   
  res = addvararg(1,2,3,4,5,6,7,8,9,10,0);

}	
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code