Easy Tutorial
❮ C Array Of Pointers C Exercise Example17 ❯

C Standard Library - <stdarg.h>

Introduction

The stdarg.h header file defines a variable type va_list and three macros, which can be used to obtain the arguments of a function when the number of arguments is unknown (i.e., variable number of arguments).

Variable argument functions are typically defined with an ellipsis (,...) at the end of the parameter list.

Library Variables

The following is the variable type defined in the stdarg.h header file:

Number Variable & Description
1 va_list <br>This is a type suitable for storing information needed by the macros va_start(), va_arg(), and va_end().

Library Macros

The following are the macros defined in the stdarg.h header file:

Number Macro & Description
1 void va_start(va_list ap, last_arg) <br>This macro initializes the ap variable, which is used together with the va_arg and va_end macros. last_arg is the last known fixed argument passed to the function, i.e., the argument before the ellipsis.
2 type va_arg(va_list ap, type) <br>This macro retrieves the next argument in the function's argument list of type type.
3 void va_end(va_list ap) <br>This macro allows a function with variable arguments that uses the va_start macro to return. The result is undefined if va_end is not called before returning from the function.
❮ C Array Of Pointers C Exercise Example17 ❯