#include <stdarg.h>
type va_arg(va_list ap, type);
va_arg expands to an expression that has the specified type and the value of the type argument. The ap parameter must have been initialized by va_start or va_copy, without an intervening invocation of va_end. You can create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns.
Each invocation of the va_arg macro modifies ap so that the values of successive arguments are returned in turn. The parameter type must be a type name such that the type of a pointer to an object that has the specified type can be obtained simply by postfixing a ‘*’ to type.
If there is no actual next argument, or if type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior of va_arg is undefined, except for the following cases:
The first invocation of the va_arg macro after that of the va_start macro returns the value of the argument after that specified by parmN. Successive invocations return the values of the remaining arguments in succession.
When calling va_arg, you must ensure that type is the promoted type of the argument, not the argument type. The following will not work as you expect
char x = va_arg(ap, char);
Because characters are promoted to integers, the above must be written:
char ch = (char)va_arg(ap, int);
va_arg conforms to ISO/IEC 9899:1990 (C90) and ISO/IEC 9899:1999 (C99).