<stdarg.h>//Header files
va_list arg access parameter list not determined part
Va_start (Arg,val);/ /Set arg_ptr to the first optional argument passed to the function argument list arg is the variable name declared, Val is the last parameter of the determined argument list
Va_arg (arg,int);//fromarg_ptrthe given location searchtypevalue, and thearg_ptrpoint to the next parameter in the list, using thetypethe range determines where the next parameter starts。 int is the type of the next parameter
Va_end (ARG);// reset pointer to NULL
#include <stdio.h> #include <stdarg.h>double aver (int val, ...) {va_list Arg;int i = 0;double sum = 0.0;va_start (ARG, Val); for (i = 0; i < val; i++) {sum = sum + va_arg (arg, int);} Va_end (ARG); return sum/val;} int main () {double ret = aver (4,3,6,4,9);p rintf ("%f", ret); return 0;}
Limitations of the mutable parameter list:
(1) All mutable parameters must be accessed and cannot be accessed only by part
(2) There is at least one named parameter that cannot be used Va_start
(3) cannot specify error parameter type in Va_arg
Averaging with a variable parameter list