C++ Programming/Code/Standard C Library/Functions/va arg

va_arg
The va_arg macros are used to pass a variable number of arguments to a function.


 * 1) First, you must have a call to va_start passing a valid va_list and the name of the last argument variable before the ellipsis ("..."). This first argument can be anything; one way to use it is to have it be an integer describing the number of parameters being passed.
 * 2) Next, you call va_arg passing the va_list and the type of the argument to be returned. The return value of va_arg is the current parameter.
 * 3) Repeat calls to va_arg for however many arguments you have.
 * 4) Finally, a call to va_end passing the va_list is necessary for proper cleanup.

This code displays 10, which is 4+3+2+1.

Here is another example of variable argument function, which is a simple printing function:

This code displays the following output when run:

Printing a string: This is a string Printing an integer: 29 Printing a character: X