ProgrammingModerateProduct company OA

What is printed?

What is printed?
struct C { int r, g, b; } c = {.b = 9, .r = 4};
printf("%d %d %d", c.r, c.g, c.b);
  1. A. 4 0 9
  2. B. 4 garbage 9
  3. C. 4 9 0
  4. D. 9 0 4

Correct answer: A. 4 0 9

Designated initialisers (C99) set members by name in any order, and any member not mentioned is zero-initialised, even in a local struct. So r = 4, g = 0, b = 9.

More C Programming questions

Exams that ask this topic