C++ Standard Library C++ STL Library

C++ - <cstdarg> (stdarg.h)



The C++ <cstdarg> header defines type and macros to access the individual arguments of a list of unnamed arguments whose number and types are not known to the called function.

A function can accept a varying number of additional arguments without specifying parameter declarations by including a comma and three dots (,...) after its regular named parameters:

return_type function_name ( parameter_declarations , ... );

To access these additional arguments the macros va_start, va_arg and va_end, declared in this header, can be used:

  • First, va_start initializes the list of variable arguments as a va_list.
  • Subsequent calls of va_arg yield the values of the additional arguments in the same order as passed to the function.
  • Finally, va_end shall be executed before the function returns.

These types and macros can be used in the current program after including the header file using - #include <cstdarg> or #include <stdarg.h>.

Library Types

TypesDescription
va_list Type to hold information about variable arguments.

Library Macros

Macro functions

MacrosDescription
va_start Initialize a variable argument list.
va_arg Retrieve next argument.
va_end End using variable argument list.
va_copy (C++11) Copy variable argument list.