ProgrammingHardProduct company OA

What is printed?

What is printed?
#define COUNT(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
printf("%zu %zu", COUNT(1, 2, 3), COUNT(7));
  1. A. 3 3
  2. B. 3 1
  3. C. 1 1
  4. D. Compilation error: a macro cannot take a variable number of arguments

Correct answer: B. 3 1

Since C99, ... in a macro collects all remaining arguments, commas included, into __VA_ARGS__. They become the initialiser of a compound-literal int array, whose sizeof divided by sizeof(int) is the number of arguments: 3, then 1.

More C Programming questions

Exams that ask this topic