function: macro va_arg () is used to pass a variable-length argument list to a function.
- First, you must call Va_start () to pass a valid argument list va_list and the first argument of the function coercion. The first parameter represents the number of arguments that will be passed.
- Second, call Va_arg () to pass the argument list va_list and the type of the parameter that will be returned. The return value of Va_arg () is the current parameter.
- Again, repeat the call to all parameters Va_arg ()
- Finally, it is necessary to call Va_end () to pass va_list to the completion of the purge.
1#include <stdio.h>2#include <stdarg.h>3 intSumint, ... );4 5 intMainvoid ) 6 {7 8 9 Ten intAnswer = SUM (4,4,3,2,1 ); One Aprintf"The answer is%d\n", answer); - - the - return(0 ); - - } + - + A intSumintnum, ...) at { - - intAnswer =0; - - va_list argptr; - in va_start (argptr, num); - to for(; num >0; num-- ) + -Answer + = Va_arg (Argptr,int ); the * va_end (argptr); $ Panax Notoginseng return(answer); - the}
This code shows that they are 4+3+2+1.
Optional independent variables for C-language functions