Latest web development tutorials

C library macro - va_end ()

C standard library - <stdarg.h> C standard library - <stdarg.h>

description

C library macrovoid va_end (va_list ap) allows the use of a function with variable parameters of va_startmacro returns. If you do not callva_end before returning from the function, the result is undefined.

statement

Here is va_end () macro statement.

void va_end(va_list ap)

parameter

  • ap - This is the same function before initialized by the va_start the va_list object.

return value

This macro does not return any value.

Examples

The following example demonstrates va_end () macro usage.

#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 result in the following:

15 * 12 =  180

C standard library - <stdarg.h> C standard library - <stdarg.h>