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);- A. 4 0
- B. 4 5
- C. 2 5
- 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
- What is printed? c int c = 0; int f(int n) { c++; return n <= 1 ? 1 : f(n / 2) + f(n - n / 2); } int main(void) { int r = f(7); printf("%d…
- Which of these loops run their body exactly for i = 4, 3, 2, 1, 0 (once each) with an unsigned i? c for (unsigned i = 5; i-- > 0; ) { /…
- What is printed? c int x = -1; unsigned y = 1; printf("%d", (x < 0 ? x : y) < 0);
- What is printed? c int a[] = {1, 2, 3, 4, 5, 6}; int s = 0; for (int p = a; p < a + 6; p += 2) s += p p[1]; printf("%d", s);
- What is printed? c int cat(int n) { if (n <= 1) return 1; int s = 0; for (int i = 0; i < n; i++) s += cat(i) cat(n - 1 - i); return s; }…
- What is printed? c char comp[31] = {0}; int cnt = 0; for (int i = 2; i <= 30; i++) { if (comp[i]) continue; cnt++; for (int j = i i; j <=…