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);- A. 4 0 9
- B. 4 garbage 9
- C. 4 9 0
- 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
- Assume 4-byte int with 4-byte alignment. What is printed? c union U { char c[5]; int i; }; printf("%zu", sizeof(union U));
- Compiled as C99 or later, what is printed? c int i = 1; for (int i = 5; i < 7; i++) { int i = 10; printf("%d ", i); } printf("%d", i);
- What is printed? c printf("%zu", sizeof("1234"));
- What is printed? c int a[8] = {0}; for (int i = 1; i < 8; i++) a[i] = a[i / 2] + (i % 2); printf("%d %d %d", a[5], a[6], a[7]);
- What is printed? c int a[] = {2, 1, 3, 2, 4, 1}, best = 0, s = 0, lo = 0; for (int hi = 0; hi < 6; hi++) { s += a[hi]; while (s > 6) s -=…
- What is wrong with this code? c char p = malloc(10); p++; free(p);