LogiQuest
Back to Variable Number of Arguments
7

What will be the output of the program?

#include <stdio.h>
#include <stdarg.h>
double avg(int n, ...) {
    va_list ap;
    double s = 0;
    int i;
    va_start(ap, n);
    for (i = 0; i < n; i++) s += va_arg(ap, double);
    va_end(ap);
    return s / n;
}
int main(void) {
    printf("%.1f\n", avg(3, 1.0, 2.0, 6.0));
    return 0;
}
Medium

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.