stdarg


1. Sum of variable arguments

#include <stdarg.h>

double sum(int count, ...)
{
    double total = 0;
    va_list ap;
    va_start(ap, count);
    for (int i = 0; i < count; i++)
    {
        total += va_arg(ap, double);
    }
    va_end(ap);
    return total;
}

int main()
{
    printf("Sum of 1.2, 3.4, and 5.6: %.2f\n", sum(3, 1.2, 3.4, 5.6));
}

2. Average of variable arguments

3. Maximum of variable arguments

4. Minimum of variable arguments

5. Printf-like function

6. Error logging with variable arguments

7. Command line argument parsing

8. Callback function with variable number of arguments

9. Function pointer with variable number of arguments

10. Macro with variable number of arguments

11. Passing a variable number of arguments to another function

12. Passing a variable number of arguments to a function pointer