LearnFrenzy
Sign in Take a free test

Variable Number of Arguments · Exercise 2 of 4

Variable Number of Arguments Predict the Output

  • 12 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run, so the answers are the real output.

Question 11 Hard

What is the output of the following program, compiled as C23?

main.c
#include <stdio.h>

#define TAG(name, ...) printf("<" name __VA_OPT__(" class='%s'") ">\n" __VA_OPT__(,) __VA_ARGS__)

int main(void) {
    TAG("p");
    TAG("div", "card");
    return 0;
}
A <p class=''> <div class='card'>
B <p> <div>
C <p> <div class='card'>
D Compilation error
Question page & discussion
Question 12 Hard

What is the output of the following program, compiled as C23?

main.c
#include <stdarg.h>
#include <stdio.h>

int product(...) {
    va_list ap;
    va_start(ap);
    int n = va_arg(ap, int);           /* the first argument is the count */
    int p = 1;
    while (n-- > 0)
        p *= va_arg(ap, int);
    va_end(ap);
    return p;
}

int main(void) {
    printf("%d %d\n", product(3, 2, 3, 7), product(0));
    return 0;
}
A 126 0
B 42 0
C 42 1
D Compilation error
Question page & discussion
Up next · Exercise 3Find the Error8 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links