Va_list Arg; Declares a variable arg of type va_list, which is used to access the indeterminate part of the parameter list;
Va_start (Arg,val); The first parameter is the variable name of Va_list, and the second parameter is the previous parameter of the indeterminate parameter;
A_arg (arg,int); returns the value of this parameter and uses var_arg to point to the next mutable parameter, the first parameter is
The variable name of the Va_list, and the second is the type of the indeterminate 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);p rintf ("%f\n", ret); return 0;} </span>
Using variable parameter list to achieve average of n number