-
-
Save st98/11380195 to your computer and use it in GitHub Desktop.
可変長引数で遊んでみるテスト。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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