ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
#define DEBUG_PRINT(fmt, ...) printf(fmt, __VA_ARGS__)
int main(void) {
    DEBUG_PRINT("%d and %d\n", 1, 2);
}
  1. A. %d and %d
  2. B. 1 and 2
  3. C. Compile-time error: variadic macros are not standard C
  4. D. fmt and __VA_ARGS__

Correct answer: B. 1 and 2

__VA_ARGS__ is a standard C99 feature for variadic macros: the ... parameter collects any extra arguments beyond fmt, and __VA_ARGS__ substitutes them (here, 1, 2) in place. The macro expands to printf("%d and %d\n", 1, 2), printing 1 and 2.

More C Programming questions

Exams that ask this topic