LogiQuest
Back to Variable Number of Arguments
8

What will be the output of the program?

#include <stdio.h>
#include <stdarg.h>
int count(const char *first, ...) {
    va_list ap;
    int n = 0;
    const char *s = first;
    va_start(ap, first);
    while (s) { n++; s = va_arg(ap, const char *); }
    va_end(ap);
    return n;
}
int main(void) {
    printf("%d\n", count("a", "b", "c", (char *)NULL));
    return 0;
}
Hard

Discussion (0)

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

Log in to join the discussion.