+ 1
What is ... in c?
So i found this code across the internet #include<stdio.h> void dynamic(int s, ...) { printf("%d ", s); } int main() { dynamic(20, 40, 60, 80); dynamic(30, 60, 90); return 0; } when executed answer is 20 30, which i understand... but in void dynamic(int s,...) what is ... ?
1 Respuesta
+ 1
It's a way to define a variadic function, i.e. a function which can accept any number of arguments.
To actually implement that behavior, your function need to use the `va_start`, `va_arg`, `va_end` macros defined in the `stdarg.h` header file. The function in the example doesn't implement that functionality, it just prints the first argument.
https://en.cppreference.com/w/c/variadic