ProgrammingVery hardProduct company OA

What is printed?

What is printed?
struct In { int a[2]; };
struct Out { struct In in[2]; int k; } q = {1, 2, 3, 4, 5};
printf("%d %d", q.in[1].a[1], q.k);
  1. A. 4 0
  2. B. 4 5
  3. C. 2 5
  4. D. Compilation error: missing braces

Correct answer: B. 4 5

When inner braces are left out, initialisers fill the members in order as if the whole aggregate were flattened: in[0].a gets 1, 2, in[1].a gets 3, 4 and k gets 5. Compilers may warn about the missing braces, but it is valid C.

More C Programming questions

Exams that ask this topic