C <stdarg.h> - va_end
The C <stdarg.h> va_end macro performs cleanup for an instance of va_list type initialized by a call to va_start or va_copy.
If there is no corresponding call to va_start or va_copy, or if va_end is not called before a function that calls va_start or va_copy returns, the behavior is undefined.
Syntax
void va_end( va_list ap );
Parameters
ap |
Specify an instance of the va_list type to clean up. |
Return Value
None.
Example:
The example below shows the usage of va_end macro function.
#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 () { printf("Sum is: %d\n", add_nums (2, 10, 20)); printf("Sum is: %d\n", add_nums (3, 10, 20, 30)); printf("Sum is: %d\n", add_nums (4, 10, 20, 30, 40)); return 0; }
The output of the above code will be:
Sum is: 30 Sum is: 60 Sum is: 100
❮ C <stdarg.h> Library