On this page
  1. va_list
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

va_list

Prev: stdarg.h | Up: stdarg.h | Next: signal.h
Rel: stdarg.h, vsnprintf()
Ref: cppreference โ€” va_list
Tags: #public #prog #c #stdlib #stdarg #tier/standard


Include

#include <stdarg.h>

Signature & Overview

va_list ap;  /* va_start, va_arg, va_end, va_copy */

Opaque type holding iteration state over variadic ... arguments.

Notes & Pitfalls

Example

#include <assert.h>
#include <stdarg.h>

static int sum_n(int count, ...) {
    va_list ap;
    va_start(ap, count);
    int total = 0;
    for (int i = 0; i < count; ++i) total += va_arg(ap, int);
    va_end(ap);
    return total;
}
int main(void) { assert(sum_n(3, 10, 20, 30) == 60); }

Linked from

Related notes