The variable parameter list is used to calculate the average value of n numbers. The number of parameter lists
Va_list arg; declares a va_list variable arg, which is used to access the undetermined part of the parameter list;
Va_start (arg, val); the first parameter is the name of the va_list variable, and the second parameter is the first parameter of the uncertain parameter;
A_arg (arg, int); returns the value of this parameter and uses var_arg to point to the next variable parameter. The first parameter is
The name of the va_list variable. The second is the type of the uncertain parameter.
<Span style = "font-size: 24px;" >#include <stdio. h> # include <stdarg. h> double average (int val ,...) {va_list arg; double sum = 0.0; va_start (arg, val); int I = 0; for (I = 0; I <val; I ++) {sum + = va_arg (arg, int);} va_end (arg); return sum/val;} int main () {double ret = average (5, 1, 2, 3, 4, 5 ); printf ("% f \ n", ret); return 0 ;}</span>