Skip to content

Instantly share code, notes, and snippets.

@st98
Created April 28, 2014 18:31
Show Gist options
  • Save st98/11380195 to your computer and use it in GitHub Desktop.
Save st98/11380195 to your computer and use it in GitHub Desktop.
可変長引数で遊んでみるテスト。
#include <stdio.h>
#include <stdarg.h>
int sum(int n, ...) {
int i;
int result = 0;
va_list args;
va_start(args, n);
for (i = 0; i < n; i++) {
result += va_arg(args, int);
}
va_end(args);
return result;
}
int main(void) {
printf("%d", sum(5, 1, 2, 3, 4, 5));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment