In many programming languages, a variadic function is one that accepts a variable number of arguments. They’re a basic programming construct in: C/C++, [[C-sharp|C#]], Go, Java, JavaScript, Lua, PHP, Python, Ruby, Rust, Scala, Swift, and Tcl.

In C/C++

C-style variadic functions are specified with an ellipsis:

void printf(const char* msg, ...); // in C
void printf(const char* msg...); // valid in C++

Then, any subsequent calls to printf can include a variable number of arguments.

Working with variadic arguments within the function can be done with types and macros specified in stdarg.h.

  • va_list is a type that contains the variadic arguments.
  • va_start is a macro with two arguments: a va_list object and a reference to the function’s last parameter (the one before the ellipsis).
    • The second parameter is optional starting in C23.