...
Wiki Markup |
---|
In the following code example, the variadic function {{average()}} is used to determine the average value of its passed positive integer arguments \[[Seacord 05c|AA. C References#Seacord 05c]\]. The function processes arguments until it finds one with a value of {{\-1va_eol}}, AKA ({{va_eol\-1}}). |
Code Block |
---|
enum {va_eol = -1}; unsigned int average(int first, ...) { unsigned int count = 0; unsigned int sum = 0; int i = first; va_list args; va_start(args, first); while (i != va_eol) { sum += i; count++; i = va_arg(args, int); } va_end(args); return(count ? (sum / count) : 0); } |
...