Variadic Functions
Functions taking a variable number of arguments, like `printf`, using `stdarg.h`.
Intermediate
#include <stdarg.h>
int sum(int n, ...) {
va_list ap; va_start(ap, n);
int s = 0; while (n--) s += va_arg(ap, int);
va_end(ap); return s;
}
No type checking — prefer fixed parameters when possible.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.