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_listis a type that contains the variadic arguments.va_startis a macro with two arguments: ava_listobject and a reference to the function’s last parameter (the one before the ellipsis).- The second parameter is optional starting in C23.