Easy Tutorial
❮ C Function Srand C Exercise Example10 ❯

C Library Macro - va_end()

C Standard Library - <stdarg.h>

Description

The C library macro void vaend(valist ap) allows a function with variable arguments which has been started by the vastart macro to return. If vaend is not called before returning from the function, the result is undefined.

Declaration

Here is the declaration for the va_end() macro.

void va_end(va_list ap)

Parameters

Return Value

This macro does not return any value.

Example

The following example demonstrates the use of the va_end() macro.

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

int mul(int, ...);

int main()
{
   printf("15 * 12 = %d\n",  mul(2, 15, 12) );

   return 0;
}

int mul(int num_args, ...)
{
   int val = 1;
   va_list ap;
   int i;

   va_start(ap, num_args);
   for(i = 0; i < num_args; i++) 
   {
      val *= va_arg(ap, int);
   }
   va_end(ap);

   return val;
}

Let's compile and run the above program, which will produce the following result:

15 * 12 =  180

C Standard Library - <stdarg.h>

❮ C Function Srand C Exercise Example10 ❯