Skip to content

Instantly share code, notes, and snippets.

@apfohl
Created November 13, 2014 17:05
Show Gist options
  • Select an option

  • Save apfohl/490d8898f3b53362b30d to your computer and use it in GitHub Desktop.

Select an option

Save apfohl/490d8898f3b53362b30d to your computer and use it in GitHub Desktop.
va_arg c example
#include <stdio.h>
#include <stdarg.h>
int sum(int argc, ...)
{
int res = 0;
va_list ap;
va_start(ap, argc);
for (int i = 0; i < argc; i++) {
res += va_arg(ap, int);
}
va_end(ap);
return res;
}
int main(void)
{
fprintf(stderr, "%d\n", sum(4, 1, 2, 3, 4));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment