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));- A. 3 3
- B. 3 1
- C. 1 1
- 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
- After the call below, what is c? c int c = 0; void perm(char s, int k, int n) { if (k == n) { c++; return; } for (int i = k; i < n; i++) {…
- What is printed? c int steps = 0; int gcd(int a, int b) { steps++; return b == 0 ? a : gcd(b, a % b); } int main(void) { int g = gcd(1071…
- What is printed? c unsigned v = 0; const char b = "10110"; while (b) v = (v << 1) | (b++ - '0'); printf("%u", v);
- With 4-byte int, what is printed? c int a[2][3][4]; printf("%zu %zu %td", sizeof a[1], sizeof a[1][2], (char )&a[1][2][3] - (char )a);
- Assume ASCII. What is printed? c int my(const char a, const char b) { while (a && a == b) { a++; b++; } return a - b; } int main(void) {…
- In what order are the nodes linked after the four calls? c struct N { int v; struct N nx; }; void ins(struct N h, struct N n) { while (h…