##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# va_start

From cppreference.com
< c‎ | variadic

Defined in header `<stdarg.h>` |  |
void va_start( va_list ap, parmN ); |  |

The `va_start` macro enables access to the variable arguments following the named argument `parmN`.

`va_start` should be invoked with an instance to a valid va_list object `ap` before any calls to va_arg.

If `parmN` is declared with `register` storage class specifier, with an array type, with a function type, or with a type not compatible with the type that results from default argument promotions, the behavior is undefined.

### [edit] Parameters

ap | - | an instance of the va_list type
parmN | - | the named parameter preceding the first variable parameter

### [edit] Expanded value

(none)

### [edit] Example

Run this code

    #include <stdio.h>
    #include <stdarg.h>

    int add_nums(int count, ...)
    {
        int result = 0;
        va_list args;
        va_start(args, count);
        for (int i = 0; i < count; ++i) {
            result += va_arg(args, int);
        }
        va_end(args);
        return result;
    }

    int main(void)
    {
        printf("%d\n", add_nums(4, 25, 25, 50, 50));
    }

Possible output:

    150

### [edit] References

- C11 standard (ISO/IEC 9899:2011):

  - 7.16.1.4 The va_start macro (p: 271-272)

- C99 standard (ISO/IEC 9899:1999):

  - 7.15.1.4 The va_start macro (p: 251-252)

- C89/C90 standard (ISO/IEC 9899:1990):

  - 4.8.1.1 The va_start macro

### [edit] See also

va_arg | accesses the next variadic function argument (function macro) [edit]
va_copy (C99) | makes a copy of the variadic function arguments (function macro) [edit]
va_end | ends traversal of the variadic function arguments (function macro) [edit]
va_list | holds the information needed by va_start, va_arg, va_end, and va_copy (typedef) [edit]
C++ documentation for va_start

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/variadic/va_start&oldid=78738"